Restricted pages according to user permission - vuejs / Standard

Asked

Viewed 641 times

1

How to allow or prevent a user from accessing a particular page? Let’s say the user is not allowed to access the page finanças. Where do I inform on the route of vuejs the access permissions of this page? Remembering that these permissions will be set in localStorage from a backend in Laravel.

  • You think it’s a good idea to have the permission validations on the frontend?

  • No. I can’t imagine what the best solution is. With the pure Aravel, I can work smoothly with these permissions, however, now with the vuejs, separating frontend and backend, I don’t know how to work these permissions since one wheel independent of the other. I saw a tutorial on youtube where, after login, with JWT, the backend sends a token to the frontend but only validation. When making a request, vuejs sends this token again and the backend validates or does not allow the execution of the operation. In short, I do not know how to authenticate, allow with Laravel and vuejs.

1 answer

0


You can use the beforeEach Router or equivalent if using another router to validate all protected routes, as per documentation, to validate the token and permissions in the backend and receive a simple response from authorized or not from the backend for the frontend to continue browsing for the route or not.

You can also define a method beforeEnter to validate a specific route:

const router = new VueRouter({
  routes: [
    {
      path: '/foo',
      component: Foo,
      beforeEnter: (to, from, next) => {
        // ...
      }
    }
  ]
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.