Initial commit

This commit is contained in:
AI
2026-05-03 07:26:12 +00:00
commit 776d374b59
57 changed files with 15968 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
export default defineNuxtRouteMiddleware(async (to) => {
const auth = useAuth()
if (!auth.isEnabled || to.meta.public) {
return
}
const requiresAuth = Boolean(to.meta.requiresAuth || (to.meta.roles && to.meta.roles.length > 0))
if (!requiresAuth) {
return
}
await auth.ensureInitialized()
if (!auth.isAuthenticated.value) {
await auth.login()
return
}
if (to.meta.roles?.length) {
const authStore = useAuthStore()
if (!authStore.hasAnyRole(to.meta.roles)) {
throw createError({
statusCode: 403,
statusMessage: 'Forbidden'
})
}
}
})