enhance (auth): clear store on 401 and redirect to /401

This commit is contained in:
Abizrh
2025-08-13 13:17:21 +07:00
parent d5c453450f
commit d8d7d61fca
3 changed files with 13 additions and 2 deletions
+11
View File
@@ -55,6 +55,10 @@ export async function xfetch(
const status = fetchError.response?.status || 500
const resJson = fetchError.data
if (status === 401 && import.meta.client) {
clearStore()
}
if (resJson?.errors) {
errors = resJson.errors
} else if (resJson?.code && resJson?.message) {
@@ -68,3 +72,10 @@ export async function xfetch(
return { success, status_code: status, body, errors, error, message }
}
}
function clearStore() {
const { $pinia } = useNuxtApp()
const userStore = useUserStore($pinia)
userStore.logout()
navigateTo('/401')
}