OptimalBits / node_acl

Access control lists for node applications
2.62k stars 369 forks source link

how to tell acl a resource is public #210

Open dadenewyyt opened 7 years ago

dadenewyyt commented 7 years ago

Hey guys ,

am having a hard time when defining acl as follows and its not working = replays with User is anuthoerized. can you give a link or an example please. this will make acl popular with the basic docuematations.

i have an api

http://localhost:3333/docs

and i have defined acl as follows on app.js

acl.allow('guest', '/docs/', ['get','put', 'delete']);

app.get('/docs/', acl.middleware(), function (req, res) {
        console.log(req);
    });

acl.allow('public', ['/', '/docs/', '/api-docs/'], 'view');

acl.whatResources('public',function(err,resources){
      console.log(resources);
 })

but when i try to access localhost:3333/docs/ it throws me error ? how do i prevent that from happening.

dimsolution commented 7 years ago

Hello,

You have to override the userId params:

const user_id = (req) => (req.feathers.user) ? req.feathers.user.id : 'anonymous'

(Save previously the anonymous user un db)

ajsnyde commented 7 years ago

Could you provide the full corrected example? I'm a little confused by how you implement the solution.