By default, passport.js only accepts username and password in its middleware.
http://passportjs.org/guide/username-password/
How do I add a third field? In my case, I need username, email, and password.
Passport's middleware is built in a way that allows you to use multiple strategies in one passport.
Configure Strategy The custom authentication strategy authenticates users by custom logic of your choosing. The strategy requires a verify callback, which is where the custom logic goes and calls done providing a user. Note that, req is always passed as the first parameter to the verify callback.
Strategies are responsible for authenticating requests, which they accomplish by implementing an authentication mechanism. Authentication mechanisms define how to encode a credential, such as a password or an assertion from an identity provider (IdP), in a request.
Passport uses serializeUser function to persist user data (after successful authentication) into session. Function deserializeUser is used to retrieve user data from session.
Very simple, you just need to add req parameter and set passReqToCallback to true
passport.use('loginpassport', new LocalStrategy({
usernameField: 'uname',
passwordField: 'upass',
passReqToCallback: true
}, function (req, username, password, done) {
var something = req.body.xxxxx;
}));
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