$auth.check() failing when Object to Object comparison is used with boolean values
AlexH-HankIT opened this issue · comments
Hi!
I'm using the currently latest version of the lib 4.1.6.
I'm having an issue with the $auth.check() method.
Take the following user object:
{id: 1, email: 'admin@example.com', roles: {'team.view': true}}
Using the auth check method yields false:
$auth.check({ 'team.view': true })
I would expect this to return true.
This is due to how the object to object comparison is done in the compare() method: https://github.com/websanova/vue-auth/blob/master/src/lib/utils.js#L45
Specifically the problem seems to be with the toArray() method not converting Booleans to an array.
A simple fix for this would be to update the toArray() method:
From
return (typeof val) === 'string' || (typeof val) === 'number' ? [val] : val;
To
return (typeof val) === 'string' || (typeof val) === 'number' ? [val] : val || (typeof val) === 'boolean' ? [val] : val
I'm not 100% sure which other issues this might cause.
Maybe you can take a look.
Thanks.
ah ya, it's trying to do dot notation since the first thing it does is split the string. Needs to be updated to do a full string check as well.
For now if you change it do dashes it should work.
Hi there,
thanks for the quick response :)
I don't think the problem is related to the dot, since it also happens with keys that don't contain a dot.
Take the following example:
{id: 1, email: 'admin@example.com', roles: {settings: true}}
Using the auth check method yields false as well:
$auth.check({ settings: true })
If i change the boolean to a string, say:
{id: 1, email: 'admin@example.com', roles: {settings: 'true'}}
Then i get true:
$auth.check({ settings: 'true' })
I would expect it to correctly compare booleans.
Would be nice, if this could be supportet, since my user object contains only booleans for the permissions.
It's just doing a indexOf check so should work for booleans.
https://github.com/websanova/vue-auth/blob/master/src/lib/utils.js#L66
Maybe double check it's true/false not 0/1 ?