blob: 6bc7071676290891dcd6d56e5f4cb60d350d6448 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { api_base, CookieNames } from "$lib/configuration";
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;
let sessionIsValid = (await fetch(api_base("_/valid-session"), {
headers: {
Cookie: CookieNames.session + "=" + cookies.get(CookieNames.session)
}
}).catch((e) => {
logError(e);
throw error(503, {
message: "We are experiencing a service distruption! Have patience while we resolve the issue."
})
})).ok;
if (sessionIsValid && isPublicRoute) {
throw redirect(302, "/home");
} else if (!sessionIsValid && !isPublicRoute) {
throw redirect(302, "/sign-in");
}
};
|