Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!