Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.beforeEach((to, from, next) => {
  2.     if (to.matched.some(record => record.meta.auth) && !localStorage.getItem('TOKEN')) {
  3.         return router.push({ name: 'login' })
  4.     }
  5.  
  6.     const user = store.state.auth.me;
  7.    
  8.     const { permissions } = user
  9.     let namePermission = []
  10.     for (let index in permissions) {
  11.         namePermission[index] = (permissions[index].name)
  12.     }
  13.  
  14.     if (to.name === 'tarefas' || to.name === 'viewTask' || to.name === 'myTasks') {
  15.         let found = namePermission.find(element => {
  16.             return element === 'tarefas'
  17.         })
  18.         if (to.meta.permissions != found)
  19.             return router.push({ name: 'not-permission' })
  20.     }
  21.  
  22.     if (to.name === 'colaboradores' || to.name === 'viewCollaborator') {
  23.         let found = namePermission.find(element => {
  24.             return element === 'colaboradores'
  25.         })
  26.         if (to.meta.permissions != found)
  27.             return router.push({ name: 'not-permission' })
  28.     }
  29.  
  30.     if (to.name === 'clientes' || to.name === 'viewClient') {
  31.         let found = namePermission.find(element => {
  32.             return element === 'cliente'
  33.         })
  34.         if (to.meta.permissions != found)
  35.             return router.push({ name: 'not-permission' })
  36.     }
  37.  
  38.     next()
  39. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement