From 38a07e3dfbda798010cc7f219abec911f747eaf7 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 3 Oct 2022 16:45:26 +0800 Subject: feat: Fully functioning i18n --- apps/kit/src/routes/(main)/+layout.server.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'apps/kit/src/routes/(main)/+layout.server.ts') diff --git a/apps/kit/src/routes/(main)/+layout.server.ts b/apps/kit/src/routes/(main)/+layout.server.ts index 6bc7071..d2eb2eb 100644 --- a/apps/kit/src/routes/(main)/+layout.server.ts +++ b/apps/kit/src/routes/(main)/+layout.server.ts @@ -3,8 +3,9 @@ import { logError } from "$lib/logger"; import { error, redirect } from "@sveltejs/kit"; import type { LayoutServerLoad } from "./$types"; -export const load: LayoutServerLoad = async ({ routeId, cookies }) => { - const isPublicRoute = routeId?.startsWith("(main)/(public)") ?? true; +export const load: LayoutServerLoad = async ({ routeId, cookies, locals }) => { + const isPublicRoute = (routeId?.startsWith("(main)/(public)") || routeId === "(main)") ?? true; + let sessionIsValid = (await fetch(api_base("_/valid-session"), { headers: { Cookie: CookieNames.session + "=" + cookies.get(CookieNames.session) @@ -15,9 +16,19 @@ export const load: LayoutServerLoad = async ({ routeId, cookies }) => { message: "We are experiencing a service distruption! Have patience while we resolve the issue." }) })).ok; + + console.log("Base Layout loaded", { + sessionIsValid, + isPublicRoute, + routeId + }); + if (sessionIsValid && isPublicRoute) { throw redirect(302, "/home"); } else if (!sessionIsValid && !isPublicRoute) { throw redirect(302, "/sign-in"); } + return { + locale: locals.locale + } }; \ No newline at end of file -- cgit v1.3