16 lines
414 B
TypeScript
16 lines
414 B
TypeScript
export default defineNuxtRouteMiddleware(async () => {
|
|
const auth = useAuth()
|
|
|
|
if ((auth.token.value || auth.tokenState.value) && !auth.user.value && !auth.isSyncingUser.value) {
|
|
try {
|
|
await auth.syncUser()
|
|
} catch (error) {
|
|
console.error('[Guest Middleware] Sync failed:', error)
|
|
}
|
|
}
|
|
|
|
if (auth.isAuthenticated.value && auth.user.value) {
|
|
return navigateTo('/dashboard')
|
|
}
|
|
})
|