blob: 5359d0222a30d6670e3e490795405ceef0148984 (
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 { 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 {};
};
|