It is the same login route.
Just 2 different approaches.
First route
router.post('/login', passport.authenticate('local',{session:false}),async (req,res) => {
console.log("
------------------------222222")
console.log(req.user);
});
and the request object has the user & is displayed.
Whereas in the second route
router.post('/login', (req, res, next) => {
passport.authenticate('local', async (err, user, info) =>{
if(err){
console.log(err);
}
console.log("
------------------------")
console.log(req.user); //undefined
if(user){
// it works here
}
else{
res.status(422).json(info);
}
})(req, res, next);
});
console.log(req.user);
shows undefined.
but the user has the user details fetched from the mongo db.
Can someone explain me please.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…