Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda