Code coverage report for api/policies/authenticated.js

Statements: 100% (7 / 7)      Branches: 100% (2 / 2)      Functions: 100% (3 / 3)      Lines: 100% (7 / 7)      Ignored: none     

All files » api/policies/ » authenticated.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                  1           18   18   18 9   9   18              
/**
 * sessionAuth
 *
 * @module      :: Policy
 * @description :: Simple policy to allow any authenticated user
 *                 Assumes that your login action in one of your controllers sets `req.session.authenticated = true;`
 * @docs        :: http://sailsjs.org/#!documentation/policies
 *
 */
module.exports = function(req, res, next) {
 
  // User is allowed, proceed to the next policy, 
  // or if this is the last policy, the controller
 
  // Initialize Passport
  passport.initialize()(req, res, function () {
    // Use the built-in sessions
    passport.session()(req, res, function () {
      // Make the user available throughout the frontend
      if (req.user) {
        res.locals.user = _.clone(req.user)
      } else {
        res.locals.user = {}
      }
      next();
    });
  });
    // User is not allowed
  // (default res.forbidden() behavior can be overridden in `config/403.js`)
  //return res.forbidden('You are not permitted to perform this action.');
};