Files
ngthanhvu d982449464 feat: add authentication modal component and user authentication logic
- Implemented AuthModal.vue for user login and registration with form handling.
- Created useAuth composable for managing user state and authentication requests.
- Added admin route middleware to protect admin routes.
- Developed admin login page with authentication checks.
- Implemented API endpoints for user management (login, logout, fetch user, register).
- Created database migrations for users table and updated movies table.
- Added utility functions for password hashing and JWT token management.
2026-07-22 04:26:58 -04:00

17 lines
428 B
TypeScript

export default defineNuxtRouteMiddleware(async (to) => {
if (!to.path.startsWith('/admin')) return
if (to.path === '/admin/login') return
const { data: user, error } = await useFetch('/api/auth/me', {
headers: useRequestHeaders(['cookie']),
})
if (error.value?.statusCode === 401 || !user.value) {
return navigateTo('/admin/login')
}
if (user.value.role !== 'admin') {
return navigateTo('/')
}
})