sessionAuth.js 685 B

123456789101112131415161718192021
  1. /**
  2. * sessionAuth
  3. *
  4. * @module :: Policy
  5. * @description :: Simple policy to allow any authenticated user
  6. * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;`
  7. * @docs :: http://sailsjs.org/#!documentation/policies
  8. *
  9. */
  10. module.exports = function(req, res, next) {
  11. // User is allowed, proceed to the next policy,
  12. // or if this is the last policy, the controller
  13. if (req.session.authenticated) {
  14. return next();
  15. }
  16. // User is not allowed
  17. // (default res.forbidden() behavior can be overridden in `config/403.js`)
  18. return res.forbidden('You are not permitted to perform this action.');
  19. };