Hi I am using nodeJs Passport npm package
I am trying to use login functionality, the code I am using is this:
let User = new mongoose.model("user", userSchema);
// use static authenticate method of model in LocalStrategy
passport.use(User.createStrategy());
// use static serialize and deserialize of model for passport session support
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.post("/login", function(req, res){
const user = new User({
username: req.body.username,
password: req.body.password
});
req.login(user, function(err){
if(err){
console.log(err);
res.redirect("/login");
}else{
// all cookies are saved, sessions working now
passport.authenticate("local")(req, res, function(){
res.redirect("/secrets");
});
}
});
});
But when I enters wrong password, it says UnAuthorized but it is also going to authenticate function and making the user authenticated.
May I know what is the issue in my code?