Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.beforeEach((to, from, next) => {
- if (to.matched.some(record => record.meta.auth) && !localStorage.getItem('TOKEN')) {
- return router.push({ name: 'login' })
- }
- const user = store.state.auth.me;
- const { permissions } = user
- let namePermission = []
- for (let index in permissions) {
- namePermission[index] = (permissions[index].name)
- }
- if (to.name === 'tarefas' || to.name === 'viewTask' || to.name === 'myTasks') {
- let found = namePermission.find(element => {
- return element === 'tarefas'
- })
- if (to.meta.permissions != found)
- return router.push({ name: 'not-permission' })
- }
- if (to.name === 'colaboradores' || to.name === 'viewCollaborator') {
- let found = namePermission.find(element => {
- return element === 'colaboradores'
- })
- if (to.meta.permissions != found)
- return router.push({ name: 'not-permission' })
- }
- if (to.name === 'clientes' || to.name === 'viewClient') {
- let found = namePermission.find(element => {
- return element === 'cliente'
- })
- if (to.meta.permissions != found)
- return router.push({ name: 'not-permission' })
- }
- next()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement