Add redirecting user to login if session cookie is not found

This commit is contained in:
qowevisa 2024-11-08 19:44:26 +02:00
parent 9dbce2b331
commit aa5a173e83

View File

@ -0,0 +1,16 @@
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = async ({ url, fetch, cookies }) => {
if (url.pathname == "/login") {
return
}
console.log("what?")
const response = await fetch("https://api.fin.qowevisa.click/api/authping");
if (!response.ok) {
cookies.delete('session', { path: "/" })
throw redirect(302, "/login");
}
}