diff options
| author | Adam Soltys <[email protected]> | 2023-04-29 23:44:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-04-29 23:44:29 -0700 |
| commit | 1f79c6594d34c19dbf6052df64d5a55be7e9e2f6 (patch) | |
| tree | b739984e64eb082cb9541621ef05425a9938b70c /src/routes/+layout.server.js | |
| parent | 92c70d8350dab3de8e786bdad1c0a8f991cd8dbc (diff) | |
| download | coinos-ui-1f79c6594d34c19dbf6052df64d5a55be7e9e2f6.tar.gz coinos-ui-1f79c6594d34c19dbf6052df64d5a55be7e9e2f6.zip | |
get user locale from db
Diffstat (limited to 'src/routes/+layout.server.js')
| -rw-r--r-- | src/routes/+layout.server.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/routes/+layout.server.js b/src/routes/+layout.server.js new file mode 100644 index 00000000..5359d022 --- /dev/null +++ b/src/routes/+layout.server.js @@ -0,0 +1,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 {}; +}; |
