25 lines
772 B
TypeScript
25 lines
772 B
TypeScript
export default defineNuxtRouteMiddleware((to) => {
|
|
if (to.meta.public) return
|
|
|
|
const { $pinia } = useNuxtApp()
|
|
|
|
if (import.meta.client) {
|
|
const userStore = useUserStore($pinia)
|
|
|
|
console.log('currRole', userStore.userRole)
|
|
console.log('isAuth', userStore.isAuthenticated)
|
|
if (!userStore.isAuthenticated) {
|
|
return navigateTo('/401')
|
|
}
|
|
|
|
// 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')
|
|
// }
|
|
}
|
|
})
|