Answer the question
In order to leave comments, you need to log in
How to display an error in passport-local-mongoose with an incorrect password and not a 401 page output?
I have such a problem that when I enter the wrong password, a page with the inscription Unauthorized is displayed. And you need to render the same page with an error, then that the username or password is not correct. I tried a little, but so I did not catch up with where to do what.
router.post('/', passport.authenticate('local'), (req, res) => {
if(status === 401) {
res.render('index', {message: 'Неверно логин или пароль'})
} else {
res.redirect('/users');
}
});
router.post('/', passport.authenticate('local'), (req, res, err) => {
if(err){
res.render('index', {message: 'Неправильный логин или пароль'});
} else {
res.redirect('/users');
}
});
Answer the question
In order to leave comments, you need to log in
Everything is written in the documentation for the module.
var User = mongoose.model('Users', UserSchema);
User.register({username:'username', active: false}, 'password', function(err, user) {
if (err) { ... }
var authenticate = User.authenticate();
authenticate('username', 'password', function(err, result) {
if (err) { ... }
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question