Skip to content

Instantly share code, notes, and snippets.

@erandirjunior
Created May 2, 2019 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erandirjunior/9f0cd07db700f4bf287067ba5bbb6b3d to your computer and use it in GitHub Desktop.
Save erandirjunior/9f0cd07db700f4bf287067ba5bbb6b3d to your computer and use it in GitHub Desktop.
Busca as permissões caso o usuário recarregue a página
import state from '../store/index'
export default ({router, store, Vue}) => {
router.beforeEach((to, from, next) => {
let permissions = store.getters['permission/getPermissions']
if (permissions.length) {
const authorization = to.meta.authorization
if (authorization) {
!permissions[authorization] ? next('/') : next(next)
} else {
next(next)
}
} else {
state()._actions['permission/loadPermissions'][0](state, 'getPermissions')
.then(() => {
permissions = store.getters['permission/getPermissions']
const authorization = to.meta.authorization
if (authorization) {
!permissions[authorization] ? next('/') : next(next)
} else {
next(next)
}
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment