Pritam Parua
Pritam Parua

Reputation: 692

Sails js policies not working

I have written a basic policies in Sails js.

in app/config/policies.js

module.exports.policies = {
   '*': 'sessionAuth'
};

in app/api/policies/sessionAuth.js

module.exports = function(req, res, next) {
console.log('reach');

  if (req.session.authenticated) {
    return next();
  }


  return res.forbidden('You are not permitted to perform this action.');
};

But when i am requesting some URL, 'reach' is not printing in console and this basic policies is not working. It is going to that controller's action which is define in route.js.

Upvotes: 1

Views: 808

Answers (1)

Mohammed Belmehdi
Mohammed Belmehdi

Reputation: 31

The problem is in your policies.js file :

You can try this

module.exports.policies = {
    //Your controller
    UserController: {
        '*': 'sessionAuth'
    }
};

Upvotes: 1

Related Questions