londonappbrewery / Authentication-Secrets

Companion Code for the Authentication Module on The Complete 2019 Web Development Bootcamp
https://www.appbrewery.co
440 stars 524 forks source link

MongooseError: Model.findOne() no longer accepts a callback ... fixed using then and catch instead of use if and else method #33

Open UmitRock opened 1 year ago

UmitRock commented 1 year ago

use new code of login post

 app.post("/login",function(req, res){
 const username = req.body.username;
 const password = req.body.password;

 User.findOne({email:username})
 .then(function(foundUser) {
     if(foundUser){
         if(foundUser.password === password){
             res.render("secrets");
         }
     }
})
.catch(function(err) {
 console.log(err);
});

});


instead of old code of login post

app.post("/login", function(req, res){ const username = req.body.username; const password = req.body.password; User.findOne({email: username}, function(err, foundUser){ if (err) { console.log(err); } else { if (foundUser){ if (foundUser.password === password){ res.render("secrets"); } } } }); });

Usenira commented 12 months ago

correct