GithubHelp home page GithubHelp logo

tenodi / permission Goto Github PK

View Code? Open in Web Editor NEW
72.0 72.0 22.0 19 KB

Npm package for hangling user permissions for routes based on roles.

Home Page: https://www.npmjs.com/package/permission

License: MIT License

JavaScript 100.00%

permission's People

Contributors

czytelny avatar tenodi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

permission's Issues

Redirects

how can I handle redirect at the control level? example if you go to url/admin take them back to sign in page if not an admin.

req.user is undefined

Hi there!
I using PassportJS to authenticate users on my site.
My routes looks like:

/routes/songs.js:

router.route('/')
  .get(Songs.renderExplore)
  .post(require('permission')(['admin']), upload.array(), Songs.create)

this is the only place where I use permission.
Also I created a field named 'role' in my User schema.
Then I debugged my app and observe that at this point:

if (req.isAuthenticated() && !req.user[role])
    throw new Error("User doesn't have property named: " + role + ". See Advantage Start in docs")

req.user is undefined
but console.log(req.session.passport) returns me:

user: '57338a9a5c52e9159fc89095'

it mean that user is authorized and there is a record in session, but req.user is undefined;
my suggestion is that permission checks req.user before it actually filled by passport.deserializeUser()

How do you use permission with Passportjs?

Thanks in advance!

add superuser support

add the ability to add a parameter to a user to be a superuser that will have access to everything

Update Version and NPM

Hi,
Thank you for creating this great package and making my coding life much easier.

ISSUE
The source code currently in NPM is not the same as the one in this repo. Both versions say 1.0.4 but the code in NPM does not support user.role as an array while the code in the GitHub Repo does.

WORKAROUND
I was able to work around this issue temporarily by doing the following:

npm install https://github.com/tenodi/permission

Thanks!

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

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);
}

Check if the roles array is an empty array

I have a config file with different roles&permissions array that can be quickly changed. Many arrays are empty and they gent sent to permissions. Permissions treats it as a normal list of permissions and lets no user pass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.