Categories
node.js passport.js

How is req.isAuthenticated() in Passport JS implemented?

In passportJS Documentation, I think passport isAuthenticated function not documented well.

How is req.isAuthenticated() in PassportJS implemented?

For any request you can check if a user is authenticated or not using this method.

app.get('/some_path',checkAuthentication,function(req,res){
//do something only if user is authenticated
});
function checkAuthentication(req,res,next){
if(req.isAuthenticated()){
//req.isAuthenticated() will return true if user is logged in
next();
} else{
res.redirect("/login");
}
}