From 7bbd3891a76d3a6da20a4aa3888e6da87e41aa6d Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 10 Oct 2022 00:42:33 +0800 Subject: refactor/fix: Small refactors/fixes, update imports --- code/app/src/routes/(main)/+layout.server.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'code/app/src/routes/(main)/+layout.server.ts') diff --git a/code/app/src/routes/(main)/+layout.server.ts b/code/app/src/routes/(main)/+layout.server.ts index d2eb2eb..0277a2c 100644 --- a/code/app/src/routes/(main)/+layout.server.ts +++ b/code/app/src/routes/(main)/+layout.server.ts @@ -1,17 +1,16 @@ import { api_base, CookieNames } from "$lib/configuration"; -import { logError } from "$lib/logger"; +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; - - let sessionIsValid = (await fetch(api_base("_/valid-session"), { + const sessionIsValid = (await fetch(api_base("_/valid-session"), { headers: { Cookie: CookieNames.session + "=" + cookies.get(CookieNames.session) } }).catch((e) => { - logError(e); + log_error(e); throw error(503, { message: "We are experiencing a service distruption! Have patience while we resolve the issue." }) @@ -25,9 +24,10 @@ export const load: LayoutServerLoad = async ({ routeId, cookies, locals }) => { if (sessionIsValid && isPublicRoute) { throw redirect(302, "/home"); - } else if (!sessionIsValid && !isPublicRoute) { + } else if (routeId === "(main)" || !sessionIsValid && !isPublicRoute) { throw redirect(302, "/sign-in"); } + return { locale: locals.locale } -- cgit v1.3