-
Notifications
You must be signed in to change notification settings - Fork 3
/
+layout.ts
32 lines (30 loc) · 942 Bytes
/
+layout.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { browser } from "$app/environment";
import { CRISP_ID } from "$lib/env";
import { userInfo, validateCredsAndFillUserInfo } from "$lib/utils/auth";
import { redirect } from "@sveltejs/kit";
import { get } from "svelte/store";
import type { LayoutLoad } from "./$types";
export const prerender = false;
export const load: LayoutLoad = async ({ url }) => {
let currentUserInfo = get(userInfo);
if (!currentUserInfo) {
await validateCredsAndFillUserInfo();
currentUserInfo = get(userInfo);
}
if (
currentUserInfo &&
!(
currentUserInfo.structures.length ||
currentUserInfo.pendingStructures.length
) &&
!url.pathname.startsWith("/auth/rattachement") &&
!url.pathname.startsWith("/auth/invitation") &&
!url.pathname.startsWith("/auth/deconnexion")
) {
throw redirect(302, "/auth/rattachement");
}
return {};
};
if (browser) {
window.tarteaucitron.user.crispID = CRISP_ID;
}