diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-03 10:45:26 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-03 10:45:26 +0200 |
| commit | 38a07e3dfbda798010cc7f219abec911f747eaf7 (patch) | |
| tree | e29b069da1ae242fb8b529c6585167888513b107 /apps/kit/src/routes/(main)/+layout.server.ts | |
| parent | 91ecf0296bfcae7b2233a199bd2e5ae13e89927d (diff) | |
| download | greatoffice-38a07e3dfbda798010cc7f219abec911f747eaf7.tar.xz greatoffice-38a07e3dfbda798010cc7f219abec911f747eaf7.zip | |
feat: Fully functioning i18n
Diffstat (limited to 'apps/kit/src/routes/(main)/+layout.server.ts')
| -rw-r--r-- | apps/kit/src/routes/(main)/+layout.server.ts | 15 |
1 files changed, 13 insertions, 2 deletions
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 |
