Answer the question
In order to leave comments, you need to log in
Why is req.acl sometimes not available?
I use mean.io for the project, during installation the system works stably, but acl in my module is sometimes not available. But the articles reference module is always available.
Here is mine where it happens:
var hasPermissions = function(req, res, next) {
req.body.permissions = req.body.permissions || ['authenticated'];
for (var i = 0; i < req.body.permissions.length; i++) {
var permission = req.body.permissions[i];
if(typeof(req.acl) === 'undefined'){
console.log('req.acl: ', req.acl);
}
if (req.acl.user.allowed.indexOf(permission) === -1) {
return res.status(401).send('User not allowed to assign ' + permission + ' permission.');
}
}
next();
};
...
app.route('/api/' + name + e + 's')
.get(controller.all)
.post(auth.requiresLogin, hasPermissions, controller.create);
...
req.acl: undefined
TypeError: Cannot read property 'user' of undefined
at hasPermissions (/home/ubuntu/workspace/mean/packages/custom/bars/server/routes/bars.js:23:16)
at Layer.handle [as handle_request] (/home/ubuntu/workspace/mean/node_modules/meanio/lib/core_modules/server/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ubuntu/workspace/mean/node_modules/meanio/lib/core_modules/server/node_modules/express/lib/router/route.js:131:13)
at /home/ubuntu/workspace/mean/packages/core/users/authorization.js:27:7
at Query.<anonymous> (/home/ubuntu/workspace/mean/packages/core/users/authorization.js:12:9)
at /home/ubuntu/workspace/mean/node_modules/kareem/index.js:177:19
at /home/ubuntu/workspace/mean/node_modules/kareem/index.js:109:16
at doNTCallback0 (node.js:407:9)
at process._tickCallback (node.js:336:13)
POST /api/orders 500 - - 10.378 ms
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question