Skip to content

Instantly share code, notes, and snippets.

@marcbachmann
Last active December 15, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcbachmann/5331158 to your computer and use it in GitHub Desktop.
Save marcbachmann/5331158 to your computer and use it in GitHub Desktop.
This is a passport LocaStrategy with custom error messages from my app.
passport.use(new LocalStrategy(
function(username, password, done) {
if (username.indexOf('@') == -1) {
username = username + '@example.com';
}
User.findOne({ 'email': username.toLowerCase()}, function(err, user) {
if (err) { return done(err); }
if (!user) {
var error = new Error('User not found or wrong Credentials');
return done(null, false, { message: error.message });
}
if (user.isValidPassword(password)) {
return done(null, user);
}
var error = new Error('Invalid password');
return done(null, false, { message: error.message });
});
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment