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

throw new MongooseError('Model.prototype.save() no longer accepts a callback'); ....... Fixing use then and catch instead of use if and else method #32

Open UmitRock opened 1 year ago

UmitRock commented 1 year ago

use new code of register post

app.post("/register", function(req, res) { const newUser = new User({ email: req.body.username, password: req.body.password });

newUser.save().then(function(){ res.render("secrets"); }).catch(function (err){ console.log(err); }); });


instead of old code of register post

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