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

When role doesn't exists getting "TypeError: Cannot read property 'length' of null" #29

Open
tensult opened this issue Aug 18, 2017 · 2 comments

Comments

@tensult
Copy link

tensult commented Aug 18, 2017

The undefined check should be done before using role grants and NoSuchRole error should thrown.

for (let i = 0; i < items.length; i++) {

@seeden
Copy link
Owner

seeden commented Aug 18, 2017

items has a default value []
what is yours value for variable items

@tensult
Copy link
Author

tensult commented Aug 18, 2017

Even I too wonder but I got following error:
/home/dilip/workspace/test/node_modules/rbac/dist/RBAC.js:602
for (var i = 0; i < items.length; i++) {
^

TypeError: Cannot read property 'length' of null
at /home/dilip/workspace/test/node_modules/rbac/dist/RBAC.js:602:34
at Memory.getGrants (/home/dilip/workspace/test/node_modules/rbac/dist/storages/Memory.js:195:16)
at RBAC._traverseGrants (/home/dilip/workspace/test/node_modules/rbac/dist/RBAC.js:595:20)
at RBAC.hasRole (/home/dilip/workspace/test/node_modules/rbac/dist/RBAC.js:758:12)

Code:

var RBAC = require('rbac').default;

const rbac = new RBAC({
  roles: ['superadmin', 'admin', 'user', 'guest'],
  permissions: {
    user: ['create', 'delete'],
    password: ['change', 'forgot'],
    article: ['create'],
    rbac: ['update']
  },
  grants: {
    guest: ['create_user', 'forgot_password'],
    user: ['change_password'],
    admin: ['user', 'delete_user', 'update_rbac'],
    superadmin: ['admin']
  }
}, function(err, rbacInstance) {
  if (err) {
    throw err;
  }
});

// Passing existing role
rbac.can('editor', 'create', 'article', (err, data) => {
    console.log(data);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant