blob: 60a2f6c6ca6852657f269bf29143b28c11aabfef (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import { auth, get } from "$lib/utils";
import { loadTranslations, locale } from '$lib/translations';
export const load = async ({ cookies, url }) => {
let user;
let token = cookies.get('token');
if (token) {
try {
user = await get('/me', auth(cookies));
} catch (e) {}
}
const { host, pathname } = url;
const defaultLocale = user?.language || 'en'; // get from cookie, user session, ...
const initLocale = locale.get() || defaultLocale; // set default if no locale already set
await loadTranslations(initLocale, pathname); // keep this just before the `return`
return { host, pathname };
};
|