aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/+layout.server.js
blob: 5273d372fbb1feb40c6574395bdd36e6d0c3eb06 (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 };
};