From 42faf7eeb6ac57a11f2c43b9c3230b869e532922 Mon Sep 17 00:00:00 2001 From: chloe Date: Thu, 19 Mar 2026 03:13:39 +0000 Subject: [PATCH] auth watch update --- Seasoned.Frontend/app/plugins/auth-watch.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Seasoned.Frontend/app/plugins/auth-watch.ts b/Seasoned.Frontend/app/plugins/auth-watch.ts index 4687746..6ce3521 100644 --- a/Seasoned.Frontend/app/plugins/auth-watch.ts +++ b/Seasoned.Frontend/app/plugins/auth-watch.ts @@ -2,12 +2,21 @@ export default defineNuxtPlugin((nuxtApp) => { const showTimeout = useState('showSessionTimeout', () => false); const isLoggedIn = useState('isLoggedIn'); - nuxtApp.hooks.hook('app:suspense:resolve', () => { - globalThis.$fetch = $fetch.create({ + nuxtApp.hook('app:created', () => { + + const originalFetch = globalThis.$fetch; + + globalThis.$fetch = originalFetch.create({ onResponseError({ response }) { - if (response.status === 401 && isLoggedIn.value) { - isLoggedIn.value = false; - showTimeout.value = true; + + if (response.status === 401) { + console.warn("Session Interceptor: Caught 401 Unauthorized."); + + const route = useRoute(); + if (route.path !== '/login') { + isLoggedIn.value = false; + showTimeout.value = true; + } } } });