Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
Trying to understand Node JS routing code

I am trying to understand one of the open source implementations to achieve SAML based SSO and I am having trouble understanding the following express router method from this class:

router.get('/', function(req, res, next) {
  console.log(arguments);
    if(req.isAuthenticated()){
        res.render('index', {
            title: 'sp1 - My Application',
            user: req.user
        });
    }else{
      console.log('not authentcated sending to authenticate');
        res.redirect('/login');
    }
});

My question is :

where exactly the code is setting `isAuthenticated` flag to true or false?

When I launched /login for the first time, I see it being false but again when I get a redirect from my idp (identity provider) this flag is true and I am going inside the if condition.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This method does come from passport authentication system,

you can check the function itself here:

/**
* Test if request is authenticated.
*
* @return {Boolean}
* @api public
*/
req.isAuthenticated = function() {
  var property = 'user';
  if (this._passport && this._passport.instance._userProperty) {
 property = this._passport.instance._userProperty;
}

 return (this[property]) ? true : false;
};
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda