1

我在 Sails js 中编写了基本策略。

在 app/config/policies.js

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

在 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.');
};

但是当我请求一些 URL 时,'reach' 没有在控制台中打印,并且这个基本策略不起作用。它将执行在 route.js 中定义的控制器操作。

4

1 回答 1

1

问题出在您的 policies.js 文件中:

你可以试试这个

module.exports.policies = {
    //Your controller
    UserController: {
        '*': 'sessionAuth'
    }
};
于 2016-01-27T17:58:10.130 回答