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;
      } else if(!(req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer')){
        return res.sendStatus(401);
      }
      validateJwt(req, res, next);
    })
    // Attach user to request
    .use(function(req, res, next) {
      User.findById(req.user._id, function (err, user) {
        if (err) return next(err);
        if (!user) return res.sendStatus(401);

        req.user = user;
        next();
      });
    });
}
/**
 * Attaches the user object to the request if authenticated
 * Otherwise returns 403
 */
Attaches the user object to the request if authenticated
Otherwise returns 403
Attaches the user object to the request if authenticated Otherwise returns 403
function isAuthenticated() {
  return compose()
    .use(function(req, res, next) {
      if(req.query && req.query.hasOwnProperty('access_token')) {
        req.headers.authorization = 'Bearer ' + req.query.access_token;
      } else if(!(req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer')){
        return res.sendStatus(401);
      }
      validateJwt(req, res, next);
    })
    .use(function(req, res, next) {
      User.findById(req.user._id, function (err, user) {
        if (err) return next(err);
        if (!user) return res.sendStatus(401);
        req.user = user;
        next();
      });
    });
}
function isAuthenticated ( ) { return compose ( ) . use ( function ( req , res , next ) { if ( req . query && req . query . hasOwnProperty ( 'access_token' ) ) { req . headers . authorization = 'Bearer ' + req . query . access_token ; } else if ( ! ( req . headers . authorization && req . headers . authorization . split ( ' ' ) [ 0 ] === 'Bearer' ) ) { return res . sendStatus ( 401 ) ; } validateJwt ( req , res , next ) ; } ) . use ( function ( req , res , next ) { User . findById ( req . user . _id , function ( err , user ) { if ( err ) return next ( err ) ; if ( ! user ) return res . sendStatus ( 401 ) ; req . user = user ; next ( ) ; } ) ; } ) ; }
Attaches the user object to the request if authenticated
 Otherwise returns 403
Attaches the user object to the request if authenticated Otherwise returns 403
// Validate jwt // allow access_token to be passed through query parameter as well // Attach user to request