nyambati / express-acl

This is a express module that enables you to implement ACL with much ease
https://nyambati.github.io/express-acl/
MIT License
227 stars 51 forks source link

roleSearchPath config doesn't work! #119

Open silpil opened 6 years ago

silpil commented 6 years ago

Hello!

I set roleSearchPath but this config is doesn't work. acl.config({ filename: 'nacl.json', roleSearchPath: 'user.role' });

//express-acl/lib/common.js objectPath.get(req, searchPath) //undefined

But searchPath set is correct 'user.role'

Example req.user: { "profile": { "gender": "", "location": "", "name": "", "website": "" }, "tokens": [], "things": [], "_id": "", "email": "", "password": "", "role": "user" }

nyambati commented 6 years ago

@smilemoreall I have set up a sample app and it seems to work fine. Would you mind sharing your code snippets and how this bug can be reproduced

silpil commented 6 years ago

@nyambati Ok, for the test I use this boilerplate (https://github.com/sahat/hackathon-starter)

I was import express-acl into the app.js const acl = require('express-acl');

Then I added config with roleSearchPath acl.config({ filename: 'nacl.json', roleSearchPath: 'user.role' });

After then I called app.use(acl.authorize);

Same I added user role in database for the user, in this way req.user.role can get 'user'

Anujraval24 commented 5 years ago

Did you got any solution?

silpil commented 5 years ago

Did you got any solution?

nope

nyambati commented 5 years ago

@smilemoreall Do you mind if we can sync on your issue. I think we may be able to get a solution that way.

bugarovic commented 5 years ago

I have got the same error. Problem is that objectPath.get searches only within direct properties of object. To support shallow (hidden, inherited) properties, objectPath must be created with withInheritedProps. const objectPath = require('object-path').withInheritedProps; I use passport in express, which create req.user property, but I'm not javascript experienced user, so I don't know if the solution is to use withInheritedProps or use another solution to make req.user properties as own.