| 1234567891011121314151617181920 |
- import { useAbility } from '@casl/vue'
- export default defineNuxtRouteMiddleware((to, _) => {
- const ability = useAbility()
- const candidates = to.matched.map((route) => route.name)
- const pages = ability.rules
- .filter((rule) => rule.action.toString() === 'display')
- .map((rule) => rule.subject.toString())
- candidates.forEach((routeName) => {
- const name: string = routeName?.toString() ?? ''
- if (name && pages.includes(name) && !ability.can('display', name)) {
- console.error('No right to see this page')
- navigateTo('/')
- }
- })
- })
|