vue-auth icon indicating copy to clipboard operation
vue-auth copied to clipboard

Issue with roles in route meta

Open TCURT15 opened this issue 4 years ago • 4 comments

Using

"vue": "^2.6.12",
"@websanova/vue-auth": "^4.1.3",
"vue-router": "^3.5.1",

Auth User

{
   "id":2,
   "first_name":"Test",
   "last_name":"User",
   "email":"[email protected]",
   "security":{
      "roles":["admin"],
      "permissions":["manage billing"]
   }
}

Vue Auth Options

options: {
    rolesKey: 'security.permissions',
}

If I run the following it returns true

this.$auth.check('manage billing')

However if I use the same permission on a route, it redirects to the forbidden route every time no matter how many different formats I have tried.

{
path: 'home',
name: 'home',
component: () => import('@app/views/Home'),
meta: {
   title: 'Home',
   auth: {
      roles: 'manage billing', 
      rolesKey: 'security.permissions' // with or without
   }
},
{
path: 'home',
name: 'home',
component: () => import('@app/views/Home'),
meta: {
   title: 'Home',
   auth: 'manage billing',
},
{
path: 'home',
name: 'home',
component: () => import('@app/views/Home'),
meta: {
   title: 'Home',
   auth: ['manage billing'],
},

Any assistance would be appreciated.

TCURT15 avatar Jul 08 '21 21:07 TCURT15

Good find, I've pushed up a fix in 4.1.4, let me know if that works :-)

websanova avatar Jul 09 '21 02:07 websanova

@websanova That did it. Thanks!

TCURT15 avatar Jul 09 '21 12:07 TCURT15

I seem to be having another issue with auth meta and child routes. If a parent route has a role defined (or in my case permission) and the child route has no auth meta defined, it throws a forbidden error when visiting the child route. However if that child route has any auth defined it works. Not a huge deal to just set the child routes to true, just wasn't sure if that was an easy fix.

Won't work:

{ 
   path: '/admin', 
   component: () => import(/* webpackChunkName: "admin" */ '@admin/views/Layout'),
   meta: {
	title: 'Dashboard',
	auth: 'see admin',
   },
   children: [
      {
	   path: 'test',
           component: () => import(/* webpackChunkName: "admin_index" */ '@admin/views/Index'),
	   meta: {
	      title: 'Dashboard',
	   }
      }
   ]
},

Works:

{ 
   path: '/admin', 
   component: () => import(/* webpackChunkName: "admin" */ '@admin/views/Layout'),
   meta: {
	title: 'Dashboard',
	auth: 'see admin',
   },
   children: [
      {
	   path: 'test',
           component: () => import(/* webpackChunkName: "admin_index" */ '@admin/views/Index'),
	   meta: {
	      title: 'Dashboard',
              auth: true
	   }
      }
   ]
},

TCURT15 avatar Jul 21 '21 22:07 TCURT15

Hmm, ya, because you have a string there, and it's checking for true, I think if you set the parent to true as well it should be fine. Otherwise it's just following the normal check, so probably just that parent check is failing.

websanova avatar Jul 24 '21 05:07 websanova