Devendra Verma Devendra Verma - 1 year ago 70
Node.js Question

Apply multiple policies in sails on a route

How to apply multiple policies in sails on routes which are generated by sails like this :

. I can apply a single policy like this in config/routes.js

'/users/:id/orders' : {
policy : 'isAuthenticated'

But how can apply more than one policy in similar manner

Answer Source

Sadly the documentation does not talk about chaining policies in routes.

As an alternative your could protect the populate action in your user controller like so: edit config/policies.js

UserController: {
    populate: ['isAuthenticated', 'isAllowed']

If you just want to apply the policy only to the orders association, you can retrieve the association parameter (/:model/:id/:association) from the req object inside the policy and handle your case:

module.exports = function(req, res, next) {
  if (req.param('association') == 'orders') {
      // do your magic
  } else {
     return next();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download