feat: Implement dedicated login page and authentication middleware

This commit is contained in:
Ryderjj89
2025-10-01 19:55:49 -04:00
parent 4aa7198406
commit ce867de7bc
5 changed files with 115 additions and 131 deletions

21
middleware/auth.ts Normal file
View File

@@ -0,0 +1,21 @@
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')
}
}
}
})