From f6baa1bb7771133a88a34c483ce18f3d28196f10 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 29 Jun 2026 14:34:22 -0500 Subject: [PATCH] refac --- src/routes/+layout.svelte | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8e368d1767..57d0a692e2 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -810,6 +810,20 @@ }); }; + const isAuthFailureResponse = async (response) => { + try { + const data = await response.clone().json(); + const detail = data?.detail; + return ( + detail === '401 Unauthorized' || + detail === 'Not authenticated' || + detail === 'Your session has expired or the token is invalid. Please sign in again.' + ); + } catch { + return true; + } + }; + const checkTokenExpiry = async () => { const exp = $user?.expires_at; // token expiry time in unix timestamp const now = Math.floor(Date.now() / 1000); // current time in unix timestamp @@ -939,7 +953,8 @@ if ( response.status === 401 && localStorage.token && - isAuthenticatedBackendFetch(input, init) + isAuthenticatedBackendFetch(input, init) && + (await isAuthFailureResponse(response)) ) { redirectToAuthAfterUnauthorized(); }