From 413b28b7599d9d085896afb60688ac52a964c9fe Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Thu, 4 Jun 2026 19:50:53 +0100 Subject: [PATCH] fix(login): redirect authenticated users before hydration Uses a raw IIFE script in that runs synchronously during HTML parsing, before Svelte hydration. Checks localStorage JWT and calls window.location.replace() for an instant redirect with no page flash. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- frontend/src/routes/login/+page.svelte | 17 +++++++++++++++++ frontend/src/routes/login/+page.ts | 23 ----------------------- 2 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 frontend/src/routes/login/+page.ts diff --git a/frontend/src/routes/login/+page.svelte b/frontend/src/routes/login/+page.svelte index fa4df21..fb09439 100644 --- a/frontend/src/routes/login/+page.svelte +++ b/frontend/src/routes/login/+page.svelte @@ -324,6 +324,23 @@ ); + + + +
diff --git a/frontend/src/routes/login/+page.ts b/frontend/src/routes/login/+page.ts deleted file mode 100644 index 51e5727..0000000 --- a/frontend/src/routes/login/+page.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { redirect } from '@sveltejs/kit'; -import { resolve } from '$app/paths'; -import type { PageLoad } from './$types'; - -export const load: PageLoad = async () => { - if (typeof window !== 'undefined') { - const token = localStorage.getItem('authToken'); - if (token) { - try { - const payload = JSON.parse(atob(token.split('.')[1])); - if (payload.exp * 1000 > Date.now()) { - if (payload.role === 'admin') { - throw redirect(302, resolve('/today')); - } - throw redirect(302, resolve('/')); - } - } catch (e) { - if (e instanceof Error && e.name === 'RedirectError') throw e; - } - } - } - return {}; -};