From aa5a173e83e9b465ff5b5285096bd9cfccbeb531 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Fri, 8 Nov 2024 19:44:26 +0200 Subject: [PATCH] Add redirecting user to login if session cookie is not found --- src/routes/+layout.server.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/routes/+layout.server.ts diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts new file mode 100644 index 0000000..130eab6 --- /dev/null +++ b/src/routes/+layout.server.ts @@ -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"); + } +}