Been working on this for a few hours now, pretty frustrating...
router.post(\'/\',
passport.authenticate(\'local-signup\', function(err, user, info) {
co
In Router.post:
router.post('/', passport.authenticate('local-signup', {
successRedirect: '/dashboad',
failureRedirect: '/',
badRequestMessage: 'Your message you want to change.', //missing credentials
failureFlash: true
}, function(req, res, next) {
...
In my case add all the field inside of config works:
passport.use(new LocalStrategy({
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true
}))
if you are using passport local mongoose as a plugin with your user model.
Try this:
passport.use(new LocalStrategy({
usernameField: 'email'
}, User.authenticate()));
Mine was spelling mistake issue.
I hade usernameFeild: 'email',
However, it should be usernameField: 'email',
There could be a mistake in field-type that's why passport.js is not able to recognize the correct field and gives error .
CORRECTION: check in .ejs file if your username and password fields correctly state type.
type="password" id="password" name="password"
//CORRECTLY SPECIFIED.
What you might have done is : Type:"text"
in ejs file and told passport to look for type:"password"
Tip : Check for spelling mistakes in type fields.
eg: type:password
in ejs & type:Password
I see your req.body
contains {password: 'password', email: 'email@email.com'}
. email
is not what passportjs is looking for, but username
is. You can either change your input names on your HTML/JS, or you can change the default parameters passportjs is looking for in req.body
. You need to apply these changes where you define your strategy.
passport.use(new LocalStrategy({ // or whatever you want to use
usernameField: 'email', // define the parameter in req.body that passport can use as username and password
passwordField: 'password'
},
function(username, password, done) { // depending on your strategy, you might not need this function ...
// ...
}
));