vue-gates icon indicating copy to clipboard operation
vue-gates copied to clipboard

Compatibility with vue-router

Open jcharcosset opened this issue 5 years ago • 1 comments

Is it planned an integration with vue-router ? Could we authorize route depend of roles and/or permissions with meta field

jcharcosset avatar Oct 23 '20 06:10 jcharcosset

Currently to integrate with Vue Router I'm putting the check in the beforeEnter callback

    {
        path: '/surveys/:survey_id/edit', component: SurveyForm,
        beforeEnter: (to, from, next) => {
            if (!router.app.$gates.hasAnyRole('Admin|Super Admin') || 
                !!router.app.$store.state.surveys.find(s => s.id === parseInt(to.params.survey_id)) {
                next('/surveys');
            }
            next();
        }
    },

It would be really nice to just pass meta: { middlewares: ['admin', 'owner'] } and if route params were available in the middleware

quantumwebco avatar Oct 25 '20 12:10 quantumwebco