Answer the question
In order to leave comments, you need to log in
PassportJS :: How to get the error text given in the strategy when calling isAuthenticate()?
Hey!
Using the local strategy passport.js
module.exports = new LocalStrategy(
{
usernameField: 'login',
passwordField: 'password'
},
(login, password, done) => {
User.findOne({ login: login }, (err, user) => {
if (err) return done(err);
if (!user || !user.checkPassword(password)) {
return done(null, false, { message: 'Incorrect username or password' });
};
return done(null, user);
});
}
);
Answer the question
In order to leave comments, you need to log in
In short here:
exports.post = function*(next) {
var self = this;
yield passport.authenticate('local', function* (err, user, info) {
if (err) throw err;
if (user === false) {
self.status = 401;
self.body = info.message;
} else {
yield self.login(user);
}
self.redirect('/');
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question