Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when calling ".can(role)" #13

Closed
riveraser opened this issue Aug 24, 2017 · 4 comments
Closed

Error when calling ".can(role)" #13

riveraser opened this issue Aug 24, 2017 · 4 comments
Labels
invalid Irrelevant or not an actual issue.

Comments

@riveraser
Copy link

riveraser commented Aug 24, 2017

This is what I am getting:

//Printing permissions
console.log(ac.getGrants());
{ ADMIN: 
   { customers: 
      { 'create:any': [Object],
        'delete:any': [Object],
        'read:any': [Object] }
      }
}

But when I do

var permission = ac.can(userRole).readAny('customers');

I am getting this error: (userRole is ADMIN)

Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot read property '$extend' of undefined
    at /apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/utils.js:58:35
    at Array.forEach (native)
    at Object.getFlatRoles (/apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/utils.js:56:15)
    at Object.getUnionAttrsOfRoles (/apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/utils.js:224:27)
    at new Permission (/apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/core/Permission.js:52:45)
    at Query._getPermission (/apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/core/Query.js:266:16)
    at Query.readAny (/apps/node-apps/figgojs-live/node_modules/accesscontrol/lib/core/Query.js:152:21)
    at /apps/node-apps/figgojs-live/Routes/AdminRoute.js:100:41
    at /apps/node-apps/figgojs-live/Utils/UniversalFunctions.js:589:13
    at /apps/node-apps/figgojs-live/node_modules/jsonwebtoken/index.js:155:18
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)
@onury
Copy link
Owner

onury commented Aug 24, 2017

When I test var permission = ac.can('ADMIN').readAny('customers');, this works with the grants you've given. See this test on runkit.

Are you sure your variable userRole is actually set to "ADMIN"? Can you do console.log(userRole) right before the line where you check for permission and see?

It seems you're calling for a non-existing role.

Also, make sure you're using the latest version (v1.5.2 as of now).

@riveraser
Copy link
Author

Hi, thanks for the fast reply and you are right, I had a TYPO in "userRole" var :-(

@onury
Copy link
Owner

onury commented Aug 24, 2017

no worries.

@onury onury closed this as completed Aug 24, 2017
@onury onury added the invalid Irrelevant or not an actual issue. label Aug 24, 2017
@onury
Copy link
Owner

onury commented Aug 24, 2017

Actually this should throw with a message indicating that the role is not found. Will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Irrelevant or not an actual issue.
Projects
None yet
Development

No branches or pull requests

2 participants