From df5402f3e762715aa88ce88898b0995dac1648e0 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 14 Nov 2022 11:05:40 +0700 Subject: fix: Align with new api to get routeId --- code/app/src/routes/(main)/+layout.server.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'code/app/src') diff --git a/code/app/src/routes/(main)/+layout.server.ts b/code/app/src/routes/(main)/+layout.server.ts index 0277a2c..5a3c1a2 100644 --- a/code/app/src/routes/(main)/+layout.server.ts +++ b/code/app/src/routes/(main)/+layout.server.ts @@ -3,8 +3,9 @@ import { log_error } from "$lib/logger"; import { error, redirect } from "@sveltejs/kit"; import type { LayoutServerLoad } from "./$types"; -export const load: LayoutServerLoad = async ({ routeId, cookies, locals }) => { - const isPublicRoute = (routeId?.startsWith("(main)/(public)") || routeId === "(main)") ?? true; +export const load: LayoutServerLoad = async ({ route, cookies, locals }) => { + const isBaseRoute = route.id === "/(main)"; + const isPublicRoute = (route.id?.startsWith("/(main)/(public)") || isBaseRoute) ?? true; const sessionIsValid = (await fetch(api_base("_/valid-session"), { headers: { Cookie: CookieNames.session + "=" + cookies.get(CookieNames.session) @@ -19,12 +20,12 @@ export const load: LayoutServerLoad = async ({ routeId, cookies, locals }) => { console.log("Base Layout loaded", { sessionIsValid, isPublicRoute, - routeId + routeId: route.id }); if (sessionIsValid && isPublicRoute) { throw redirect(302, "/home"); - } else if (routeId === "(main)" || !sessionIsValid && !isPublicRoute) { + } else if (isBaseRoute || !sessionIsValid && !isPublicRoute) { throw redirect(302, "/sign-in"); } -- cgit v1.3