From 56ee875e21cb3b137a5aa1eca6eb3c0731b14045 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 1 Jul 2026 01:46:36 -0500 Subject: [PATCH] refac --- src/routes/+layout.svelte | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 57d0a692e2..1e797d2928 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -810,18 +810,17 @@ }); }; - 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 isCurrentSessionUnauthorized = async (originalFetch) => { + return originalFetch(`${WEBUI_API_BASE_URL}/auths/`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${localStorage.token}` + }, + credentials: 'include' + }) + .then((res) => res.status === 401) + .catch(() => false); }; const checkTokenExpiry = async () => { @@ -954,7 +953,7 @@ response.status === 401 && localStorage.token && isAuthenticatedBackendFetch(input, init) && - (await isAuthFailureResponse(response)) + (await isCurrentSessionUnauthorized(originalFetch)) ) { redirectToAuthAfterUnauthorized(); }