Is there any way to allow a user to register on the local strategy with his password, email and name?
Every example I could find online only use name/password or email/p
This has actually nothing to do with passport
and is pretty simple, assuming you are using body-parser
. Make sure you have an input field
in your form with the attribute name="name"
where you register the user's name like:
In your routing, you can access this field with req.body.name
:
passport.use('local-signup', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
//are there other options?
//emailField did not seem to do anything
passReqToCallback: true
},
function(req, email, password, done) {
//check if email not already in database
//create new user using "email" and "password"
//I want an additional parameter here "name"
user.email = email;
user.password = password; // Do some hashing before storing
user.name = req.body.name;
}));
So you can add as many form input fields as you want, access them by the value of the name attribute. A Second example would be:
// Access them by
user.city = req.body.city;
user.country = req.body.country;