What's the object we pass to passport.use middleware?

Hello, when I was configuring my passport.js authentication based on youtube tutorial I bumped into this line of code:

  passport.use(new LocalStrategy({usernameField: 'email'}, authenticateUser));

So what is this first argument in the LocalStrategy brackets ({usernameField: 'email'})? What is it defining?

Your authenticateUser callback expects username and password to be passed by passportJS. With {usernameField: 'email'} you’re specifying where to find username.

1 Like

Do I need to specify that when my veryfing callback looks like this:

const authenticateUser = async (email, password, done) => {
    const user = getUserByEmail(email)
    if(user === null || user === undefined) {
      return done(null, false, {message: 'No user with that email'})

    try {
      if (await bcrypt.compare(password, user.password)) {
        return done(null, user)
      } else {
        return done(null, false, {message: 'Password incorrect'})
    } catch (e){
      return done(e)

I’m pointing to the email, and password so why I should assign email to usernameField variable if I’m not using it anywhere (I mean this usernameField variable)?