Answer the question
In order to leave comments, you need to log in
How did those specified in the settings output errors in the passport-local-mongoose module?
I have a question, I did authorization using this passport-local-mongoose module and there was such a problem that I can’t figure out how to make the errors that I specified in the options of the module display them, and didn’t I write these errors myself in the message?
router.post('/', (req, res) => {
let authenticate = User.authenticate();
authenticate(req.body.username, req.body.password, (err, result) => {
if (err) {
console.log(err);
return res.render('index', {message: err})
}
if (result === false){
return res.render('index', {message: 'Неверный логи или пароль'})
}
passport.authenticate('local')(req, res, function () {
res.redirect('/users');
});
})
});
let mongoose = require('../bin/mongoose'),
passportLocalMongoose = require('passport-local-mongoose'),
Schema = mongoose.Schema;
let schema = new Schema({
username: {
type: String,
},
password: {
type: String,
},
created: {
type: Date,
default: Date.now
}
});
schema.plugin(passportLocalMongoose, {
errorMessages: {
UserExistsError: 'Данный пользователь уже зарегестрировался',
IncorrectPasswordError: 'Неправильный логин или пароль',
IncorrectUsernameError: 'Неправильный логин или пароль'
}
});
module.exports = mongoose.model('User', schema);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question