diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-09-24 09:37:46 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-09-24 09:37:46 +0200 |
| commit | bee20bccda598b833ced376856351727f385108b (patch) | |
| tree | 8bc8f4eda380d389d54d51a9f8b80fc022aa548c /apps | |
| parent | ccb88c7e04b731b71fef33ea34082ea12f10ad3e (diff) | |
| download | greatoffice-bee20bccda598b833ced376856351727f385108b.tar.xz greatoffice-bee20bccda598b833ced376856351727f385108b.zip | |
feat: Add LocaleSwitcher globally
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/kit/src/routes/+layout.svelte | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/kit/src/routes/+layout.svelte b/apps/kit/src/routes/+layout.svelte index 688673b..cbb4856 100644 --- a/apps/kit/src/routes/+layout.svelte +++ b/apps/kit/src/routes/+layout.svelte @@ -1,18 +1,27 @@ <script lang="ts"> import "../app.pcss"; - import {afterNavigate, beforeNavigate, goto} from "$app/navigation"; - import {is_active} from "$lib/session"; - import type {Navigation} from "@sveltejs/kit"; - import {setLocale} from "$lib/i18n/i18n-svelte"; - import {onMount} from "svelte"; - import type {LayoutData} from "./$types"; + import { afterNavigate, beforeNavigate, goto } from "$app/navigation"; + import { is_active } from "$lib/session"; + import type { Navigation } from "@sveltejs/kit"; + import { setLocale } from "$lib/i18n/i18n-svelte"; + import { onMount } from "svelte"; + import type { LayoutData } from "./$types"; + import LocaleSwitcher from "$lib/components/locale-switcher.svelte"; export let data: LayoutData; onMount(() => setLocale(data.locale)); async function redirect_if_necessary(ticket: Navigation) { const sessionIsValid = await is_active(); - const isPublicRoute = ticket.to?.routeId?.startsWith("(public)"); + // TODO: ticket.to can be empty while navigating, so coalesce could probably cause non-public routes to cause a redir to /login... + const isPublicRoute = + ticket.to?.routeId?.startsWith("(public)") ?? true; + + console.log("redir: ", { + isPublicRoute, + sessionIsValid, + }); + if (sessionIsValid && isPublicRoute) { await goto("/home"); } else if (!sessionIsValid && !isPublicRoute) { @@ -27,4 +36,5 @@ beforeNavigate(redirect_if_necessary); </script> -<slot></slot>
\ No newline at end of file +<LocaleSwitcher /> +<slot /> |
