generators/app/templates/server/lib/auth(auth)/auth.service.js
function isAuthenticated() {
  return compose()
    // Validate jwt
    .use(function (req, res, next) {
      // allow access_token to be passed through query parameter as well
      if (req.query && req.query.hasOwnProperty('access_token')) {
        req.headers.authorization = 'Bearer ' + req.query.access_token;
      }

      validateJwt(req, res, next);
    })

    .use(function (req, res, next) { // Attach userInfo to request
      // return if this request has already been authorized
      if (req.hasOwnProperty('userInfo')) {
        return next();
      }

      // load user model on demand
      var User = require('../../api/user/user.model').model;

      // read the user id from the token information provided in req.user
      User.findOne({_id: req.user._id, active: true}, function (err, user) {
        if (err) {
          return next(err);
        }

        if (!user) {
          res.unauthorized();
          return next();
        }

        // set the requests userInfo object as the authenticated user
        req.userInfo = user;
        next();
      });
    });
}
function isAuthenticated() {
  return compose()
    // Validate jwt
    .use(function (req, res, next) {
      // allow access_token to be passed through query parameter as well
      if (req.query && req.query.hasOwnProperty('access_token')) {
        req.headers.authorization = 'Bearer ' + req.query.access_token;
      }

      validateJwt(req, res, next);
    })

    .use(function (req, res, next) { // Attach userInfo to request
      // return if this request has already been authorized
      if (req.hasOwnProperty('userInfo')) {
        return next();
      }

      // load user model on demand
      var User = require('../../api/user/user.model').model;

      // read the user id from the token information provided in req.user
      User.findOne({_id: req.user._id, active: true}, function (err, user) {
        if (err) {
          return next(err);
        }

        if (!user) {
          res.unauthorized();
          return next();
        }

        // set the requests userInfo object as the authenticated user
        req.userInfo = user;
        next();
      });
    });
}
function isAuthenticated ( ) { return compose ( ) // Validate jwt . use ( function ( req , res , next ) { // allow access_token to be passed through query parameter as well if ( req . query && req . query . hasOwnProperty ( 'access_token' ) ) { req . headers . authorization = 'Bearer ' + req . query . access_token ; } validateJwt ( req , res , next ) ; } ) . use ( function ( req , res , next ) { // Attach userInfo to request // return if this request has already been authorized if ( req . hasOwnProperty ( 'userInfo' ) ) { return next ( ) ; } // load user model on demand var User = require ( '../../api/user/user.model' ) . model ; // read the user id from the token information provided in req.user User . findOne ( { _id : req . user . _id , active : true } , function ( err , user ) { if ( err ) { return next ( err ) ; } if ( ! user ) { res . unauthorized ( ) ; return next ( ) ; } // set the requests userInfo object as the authenticated user req . userInfo = user ; next ( ) ; } ) ; } ) ; }
Attaches the user object to the request if authenticated otherwise returns 403
@return {express.middleware}
Attaches the user object to the request if authenticated otherwise returns 403