Add authentication system with login, password reset, and member area
This commit is contained in:
29
middleware/auth.js
Normal file
29
middleware/auth.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
// Check if route requires auth
|
||||
const protectedRoutes = ['/mitgliederbereich', '/cms']
|
||||
const requiresAuth = protectedRoutes.some(route => to.path.startsWith(route))
|
||||
|
||||
if (!requiresAuth) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check auth status
|
||||
try {
|
||||
const { data: auth } = await useFetch('/api/auth/status')
|
||||
|
||||
if (!auth.value || !auth.value.isLoggedIn) {
|
||||
return navigateTo('/login?redirect=' + to.path)
|
||||
}
|
||||
|
||||
// Check role for CMS
|
||||
if (to.path.startsWith('/cms')) {
|
||||
const isAdmin = auth.value.role === 'admin' || auth.value.role === 'vorstand'
|
||||
if (!isAdmin) {
|
||||
return navigateTo('/mitgliederbereich')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return navigateTo('/login?redirect=' + to.path)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user