Closed ruelluna closed 4 years ago
Seems like if I treat it as a middleware, it will hit in every route. So instead, I had it as a plugin:
export default ({ store, redirect, $laravel }, inject) => {
inject('isAdmin', () => {
if( !$laravel.hasRole('admin') ) {
redirect('/')
}
})
}
..and called into each component like this.$isAdmin
.
But then again, $laravel
seems to be undefined.
@ruelluna Laravel Permissions in injected into the Vue instance, try to access it by:
import Vue from 'vue'
export default ({ store, redirect }, inject) => {
inject('isAdmin', () => {
if( !Vue.prototype.$laravel.hasRole('admin') ) {
redirect('/')
}
})
}
Hi William,
can you provide a cleary example for use hasRole as middleware in page?
Thanks
@Wit3 I invite you to try the new version of Vue Gates! 🎉
Great stuff you got here!
A question though, I'm trying to make a middleware on Nuxt.js that is role-based. It is basically easier to have like,
rather than checking each and every component of what role the user has
So far, I've created a
role-admin.js
middeware withBut the thing is,
context.app.$laravel
is undefined.Am I missing something? Thanks for your help!