Files
Seasoned/Seasoned.Frontend/app/plugins/auth-watch.ts
2026-03-19 03:00:09 +00:00

15 lines
457 B
TypeScript

export default defineNuxtPlugin((nuxtApp) => {
const showTimeout = useState('showSessionTimeout', () => false);
const isLoggedIn = useState('isLoggedIn');
nuxtApp.hooks.hook('app:suspense:resolve', () => {
globalThis.$fetch = $fetch.create({
onResponseError({ response }) {
if (response.status === 401 && isLoggedIn.value) {
isLoggedIn.value = false;
showTimeout.value = true;
}
}
});
});
});