auth watch update
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user