From 5248bf5ffca4c8b3303de4c73d11c9f7f0cfde13 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 21 Jan 2026 15:00:02 -0800 Subject: redirect on invalid token --- src/routes/+layout.server.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/routes/+layout.server.ts') diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 584e836c..c1f77695 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -3,7 +3,8 @@ import { loadTranslations, locales, } from "$lib/translations/index"; -import { auth, get, sleep } from "$lib/utils"; +import { auth, get, isInvalidTokenError, sleep } from "$lib/utils"; +import { redirect } from "@sveltejs/kit"; export const load = async ({ cookies, request, url }) => { const { host, pathname } = url; @@ -13,8 +14,22 @@ export const load = async ({ cookies, request, url }) => { try { user = await get("/me", auth(cookies)); } catch (e) { - if (e.message.startsWith("Rate")) await sleep(3000); - user = await get("/me", auth(cookies)); + const { message } = e as Error; + if (message.startsWith("Rate")) { + await sleep(3000); + try { + user = await get("/me", auth(cookies)); + } catch (retryError) { + if (isInvalidTokenError(retryError) && pathname !== "/logout") { + redirect(307, "/logout"); + } + throw retryError; + } + } else if (isInvalidTokenError(e) && pathname !== "/logout") { + redirect(307, "/logout"); + } else { + throw e; + } } } -- cgit v1.2.3