Unable to show login messages when username is correct and password is wrong
I have just started learning express. I am adding basic authentication using passport js. I have followed this documentation. It is working a little bit odd on error messages. When the username is correct and password is wrong, it doesn't add any messages to session. It just has basic info like path.
app.post("/login",(req,res)=>{
const user = new User({
username:req.body.username,
password:req.body.password
});
console.log(req.session);
req.login(user,function(err){
if(err){
console.log(err);
}
else{
passport.authenticate("local",{ failureRedirect: '/login', failureMessage: true })(req,res,function(){
res.redirect("/secrets");
});
}
});
});
When the username is wrong, it adds message to session but it doesn't reload properly. it doesn't reload at all to "/login". I have to literally kill the process and then this session data is added.
It doesn't seem to work at all. Kindly help me with dealing both of errors, i.e. right username wrong password and wrong username wrong password.
Comments
Post a Comment