Starting over
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const token = useCookie('auth_token')
|
||||
|
||||
if (!token.value && to.path === '/admin') {
|
||||
// Redirect to login page if not authenticated and trying to access admin
|
||||
return navigateTo('/login')
|
||||
}
|
||||
|
||||
if (token.value) {
|
||||
try {
|
||||
// Verify token with server
|
||||
await $fetch('/api/auth/verify')
|
||||
} catch {
|
||||
// If token is invalid, clear it and redirect to login
|
||||
token.value = ''
|
||||
if (to.path === '/admin') {
|
||||
return navigateTo('/login')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user