express-acl icon indicating copy to clipboard operation
express-acl copied to clipboard

roleSearchPath config doesn't work!

Open silpil opened this issue 7 years ago • 6 comments

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" }

silpil avatar Oct 08 '18 13:10 silpil

@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

nyambati avatar Oct 08 '18 14:10 nyambati

@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'

silpil avatar Oct 10 '18 10:10 silpil

Did you got any solution?

Anujraval24 avatar Jan 01 '19 13:01 Anujraval24

Did you got any solution?

nope

silpil avatar Feb 19 '19 10:02 silpil

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

nyambati avatar Feb 19 '19 13:02 nyambati

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.

bugarovic avatar Apr 03 '19 17:04 bugarovic