is-logged-in.js 839 B

123456789101112131415161718192021222324252627
  1. /**
  2. * is-logged-in
  3. *
  4. * A simple policy that allows any request from an authenticated user.
  5. *
  6. * For more about how to use policies, see:
  7. * https://sailsjs.com/config/policies
  8. * https://sailsjs.com/docs/concepts/policies
  9. * https://sailsjs.com/docs/concepts/policies/access-control-and-permissions
  10. */
  11. module.exports = async function (req, res, proceed) {
  12. // If `req.me` is set, then we know that this request originated
  13. // from a logged-in user. So we can safely proceed to the next policy--
  14. // or, if this is the last policy, the relevant action.
  15. // > For more about where `req.me` comes from, check out this app's
  16. // > custom hook (`api/hooks/custom/index.js`).
  17. if (req.me) {
  18. return proceed();
  19. }
  20. //--•
  21. // Otherwise, this request did not come from a logged-in user.
  22. return res.unauthorized();
  23. };