Sometimes, we want to pass additional form fields to the local authentication strategy Using Node.js Passport.js.
In this article, we’ll look at how to pass additional form fields to the local authentication strategy Using Node.js Passport.js.
How to pass additional form fields to the local authentication strategy Using Node.js Passport.js?
To pass additional form fields to the local authentication strategy Using Node.js Passport.js, we set the passReqToCallback
option to true
.
For instance, we write
passport.use(new LocalStrategy({
usernameField: 'email',
passReqToCallback: true
},
(req, email, password, done) =>{
// ...
}
));
to create a LocalStrategy
instance with an object that has passReqToCallback
set to true
.
As a result, the middleware function in the 2nd argument would have the full req
object from other middlewares before it passed into it.
Conclusion
To pass additional form fields to the local authentication strategy Using Node.js Passport.js, we set the passReqToCallback
option to true
.