✨ feat (rbac): implement role-based access control
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
if (to.meta.public) return
|
||||
|
||||
const { $pinia } = useNuxtApp()
|
||||
|
||||
if (import.meta.client) {
|
||||
@@ -10,9 +12,13 @@ export default defineNuxtRouteMiddleware((to) => {
|
||||
return navigateTo('/auth/login')
|
||||
}
|
||||
|
||||
const allowedRoles = to.meta.roles as string[] | undefined
|
||||
if (allowedRoles && !allowedRoles.includes(userStore.userRole)) {
|
||||
return navigateTo('/unauthorized')
|
||||
}
|
||||
// const allowedRoles = to.meta.roles as string[] | undefined
|
||||
// if (allowedRoles && !allowedRoles.includes(userStore.userRole)) {
|
||||
// return navigateTo('/unauthorized')
|
||||
// }
|
||||
// const allowedRoles = to.meta.roles as string[] | undefined
|
||||
// if (allowedRoles && !userStore.userRole.some((r) => allowedRoles.includes(r))) {
|
||||
// return navigateTo('/unauthorized')
|
||||
// }
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user