diff options
| author | Adam Soltys <[email protected]> | 2026-01-21 15:00:02 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-01-21 15:00:02 -0800 |
| commit | 5248bf5ffca4c8b3303de4c73d11c9f7f0cfde13 (patch) | |
| tree | 33ad949937238d4b8d286829bf6418aed235fcf5 /src/routes/+layout.server.ts | |
| parent | 76bbaa296e2fa5a0bf51e15dd8b51011b0ee4a1e (diff) | |
| download | coinos-ui-5248bf5ffca4c8b3303de4c73d11c9f7f0cfde13.tar.gz coinos-ui-5248bf5ffca4c8b3303de4c73d11c9f7f0cfde13.zip | |
redirect on invalid token
Diffstat (limited to 'src/routes/+layout.server.ts')
| -rw-r--r-- | src/routes/+layout.server.ts | 21 |
1 files changed, 18 insertions, 3 deletions
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; + } } } |
