forked from appwrite/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path+layout.ts
47 lines (41 loc) · 1.38 KB
/
+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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import '@appwrite.io/pink';
import '@appwrite.io/pink-icons';
import 'tippy.js/dist/tippy.css';
import LogRocket from 'logrocket';
import { sdk } from '$lib/stores/sdk';
import { redirect } from '@sveltejs/kit';
import { Dependencies } from '$lib/constants';
import type { LayoutLoad } from './$types';
export const ssr = false;
export const load: LayoutLoad = async ({ depends, url }) => {
depends(Dependencies.ACCOUNT);
try {
const account = await sdk.forConsole.account.get<{ organization?: string }>();
LogRocket.identify(account.$id, {
name: account.name,
email: account.email
});
return {
account,
organizations: await sdk.forConsole.teams.list()
};
} catch (error) {
const acceptedRoutes = [
'/login',
'/register',
'/recover',
'/invite',
'/auth/magic-url',
'/auth/oauth2/success',
'/auth/oauth2/failure',
'/card',
'/hackathon'
];
if (!acceptedRoutes.some((n) => url.pathname.startsWith(n))) {
const redirectUrl =
url.pathname && url.pathname !== '/' ? `redirect=${url.pathname}` : '';
const path = url.search ? `${url.search}&${redirectUrl}` : `?${redirectUrl}`;
redirect(303, `/login${path}`);
}
}
};