Use email with Passport-local. Previous help not working Use email with Passport-local. Previous help not working express express

Use email with Passport-local. Previous help not working


It seems to me you just changed the name of the argument in the LocalStrategy callback to "email". Passport doesn't automagically know that the field is named email though, you have to tell it.

By default, LocalStrategy expects to find credentials in parameters named username and password. If your site prefers to name these fields differently, options are available to change the defaults.

passport.use(new LocalStrategy({    usernameField: 'email',    passwordField: 'passwd'  },  function(username, password, done) {    // ...  }));

Source


As an addition for those who cannot get it to work with the above solution (like me), try this instead:

passport.use(  new LocalStrategy(    {      passReqToCallback: true,    },    (request, username, password, next) => {      User.findOne({ email: username })      ...