aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/+layout.server.js
blob: 91d24d3d49a584e13563da5ecf4cf6f276090903 (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 let load = async ({ cookies, url }) => {
  let user;
  let token = cookies.get("token");
  if (token) {
    try {
      user = await get("/me", auth(cookies));
    } catch (e) {}
  }

  let { host, pathname } = url;
  let locale = user?.language || "en";
  await loadTranslations(locale, pathname);
  return { host, pathname };
};