diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-09-20 09:24:27 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-09-20 09:24:27 +0200 |
| commit | a9072370ca1eb9a5cce928b1d487db0f307edea6 (patch) | |
| tree | 59c3c23df930a8b5f888dc7813923abf4ceefed4 /apps/kit/src/routes/+layout.svelte | |
| parent | 56fa963a1d63cbe0bf28e29e717cceaa417c45c1 (diff) | |
| download | greatoffice-a9072370ca1eb9a5cce928b1d487db0f307edea6.tar.xz greatoffice-a9072370ca1eb9a5cce928b1d487db0f307edea6.zip | |
feat: Move old apps into it's own directory
Diffstat (limited to 'apps/kit/src/routes/+layout.svelte')
| -rw-r--r-- | apps/kit/src/routes/+layout.svelte | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/apps/kit/src/routes/+layout.svelte b/apps/kit/src/routes/+layout.svelte new file mode 100644 index 0000000..ee76da9 --- /dev/null +++ b/apps/kit/src/routes/+layout.svelte @@ -0,0 +1,23 @@ +<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"; + + async function redirect_if_necessary(ticket: Navigation) { + const sessionIsValid = await is_active(); + const isPublicRoute = ticket.to?.routeId?.startsWith("(public)"); + if (sessionIsValid && isPublicRoute) { + await goto("/home"); + } else if (!sessionIsValid && !isPublicRoute) { + await goto("/login"); + } + } + + // This should probably be removed in favor of the logic in layout.server.ts. + // That requires a more sophisticated server side implementation of session handling, + // and i don't want that tbh, i want to stay as much in the browser as possible. + afterNavigate(redirect_if_necessary); + beforeNavigate(redirect_if_necessary); +</script> +<slot></slot>
\ No newline at end of file |
