I'm using passport-local to provide local authentication on my node app. However, I would like to change this to authenticate with an email address rather than a username. Is there a way to do this?
Thank you.
You must first change the default username field to email with { usernameField: 'email' } you can then run a database search based on the email and check the password:
passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, password, done) {
UserModel.findOne({ email: email }, function(err, user) {
// Check password functionality
})
})
Since you have to implement the validation yourself (in the LocalStrategy
verifier callback), you can pass it anything you like:
passport.use(new LocalStrategy(function(email, password, done) {
// search your database, or whatever, for the e-mail address
// and check the password...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With