20 lines
584 B
TypeScript
20 lines
584 B
TypeScript
export default defineNuxtPlugin(async () => {
|
|
const auth = useAuth()
|
|
|
|
if ((auth.token.value || auth.tokenState.value) && !auth.user.value) {
|
|
try {
|
|
await auth.syncUser()
|
|
} catch (error) {
|
|
const status = (error as any)?.statusCode || (error as any)?.status || (error as any)?.response?.status
|
|
|
|
if (status === 401 || status === 403) {
|
|
console.error('[Auth Plugin] Sync failed with authentication error, keeping session state:', error)
|
|
return
|
|
}
|
|
|
|
console.error('[Auth Plugin] Sync failed:', error)
|
|
auth.logout()
|
|
}
|
|
}
|
|
})
|