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

Allow the req.user[role] to be an array of roles. #3

Closed
snlacks opened this issue Mar 9, 2016 · 3 comments
Closed

Allow the req.user[role] to be an array of roles. #3

snlacks opened this issue Mar 9, 2016 · 3 comments

Comments

@snlacks
Copy link

snlacks commented Mar 9, 2016

What about something like this in index.js? (This is not the most elegant algorithm nor did I run it yet. It's just an idea at this point.)

if (req.isAuthenticated()) {
  if (!roles || roles.indexOf(req.user[role]) > -1){
    after(req, res, next, permission.AUTHORIZED);
  } else if (req.user[role].hasProperty('forEach)) {
    var perm = permission.NOT_AUTHORIZED;
    req.user[role].forEach(function(userRole, i){
        if(!roles || roles.indexOf(userRole) > -1) perm = permission.AUTHORIZED;
    }
    after(req, res, next, perm);
 } else {
    after(req, res, next, permission.NOT_AUTHORIZED);
  }
}
else {
  after(req, res, next, permission.NOT_AUTHENTICATED);
}
@tenodi
Copy link
Owner

tenodi commented May 19, 2016

Hey, sorry for not answering soon enough. I'll take a look into it these days.

@Globik
Copy link

Globik commented Jun 20, 2016

It would be nice with combination of mongodb's built-in roles and access grunts.

@czytelny
Copy link
Collaborator

it's added

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

4 participants