websanova / vue-auth

A simple light-weight authentication library for Vue.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with reading rolesKey

platinumsistemas opened this issue · comments

Hi, currently I'm using the "@websanova/vue-auth": "^2.21.10-beta" for login and I'm trying to make it filter access through roles.

The issue that I have currently is that my user object has a role attribute that is not read by the rolesKey correctly.

Here is the $auth.user()

id: 2
name: "Administrador"
phone: null
role: 1
....

using the next configuration :

options: {rolesKey: 'role'}

meta: {
            auth: {role: 1, redirect: {name: 'login'}, forbiddenRedirect: '/administrador'}
          },

The problem is that I when I use the check Method, this are the results:

    console.log(this.$auth.check()) true
    console.log(this.$auth.check(1)) false
    console.log(this.$auth.check("1")) false
    console.log(this.$auth.check("admin")) false

I would love to know if I need to make the role an object or if I should use a string.

It looks correct to me, but that's a a pretty old version, best to update to latest, will probably take less time than trying to fix that :-)

My error was in the
auth: {role: 1, redirect: {name: 'login'}, forbiddenRedirect: '/administrador'}
it was roles as a standard property, not as the name of the property of the object
auth: {roles: 1, redirect: {name: 'login'}, forbiddenRedirect: '/administrador'}

Thanks both for the response and this great package.