auth watch update

This commit is contained in:
2026-03-19 03:13:39 +00:00
parent f3d6df2f82
commit 42faf7eeb6

View File

@@ -2,12 +2,21 @@ export default defineNuxtPlugin((nuxtApp) => {
const showTimeout = useState('showSessionTimeout', () => false); const showTimeout = useState('showSessionTimeout', () => false);
const isLoggedIn = useState('isLoggedIn'); const isLoggedIn = useState('isLoggedIn');
nuxtApp.hooks.hook('app:suspense:resolve', () => { nuxtApp.hook('app:created', () => {
globalThis.$fetch = $fetch.create({
const originalFetch = globalThis.$fetch;
globalThis.$fetch = originalFetch.create({
onResponseError({ response }) { onResponseError({ response }) {
if (response.status === 401 && isLoggedIn.value) {
isLoggedIn.value = false; if (response.status === 401) {
showTimeout.value = true; console.warn("Session Interceptor: Caught 401 Unauthorized.");
const route = useRoute();
if (route.path !== '/login') {
isLoggedIn.value = false;
showTimeout.value = true;
}
} }
} }
}); });