-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
So right now my strategy is this:
passport.use(new LocalStrategy({
usernameField: 'username',
passwordField: 'userpassword'
}, function(username, password, callback) {
console.log('authenticating.. : ' + username)
User.findOne({username: username}, function(err, user) {
if (err) return callback(err);
// make sure the user exists
if (!user) {
return callback(null, false, {message: 'Username not found'});
}
// test for a matching password
user.comparePassword(password, function(err, isMatch) {
if (err) return callback(err);
// check if password was a match
if (isMatch) {
return callback(null, user);
}
// password incorrect
return callback(null, false, {message: 'Password not found'});
});
});
}
And in my app.js:
app.post('/signin', passport.authenticate('local', {successRedirect: '/dashboard',
failureRedirect: '/signin',
failureFlash: true}));
In a case when user enters no credentials at all, or just one of username or password, he sees the flash message Missing Credentials. I'd like the user to see one of my messages in my strategy Username not found or Password not found.
How does one do it?
Metadata
Metadata
Assignees
Labels
No labels