Passport js local strategy custom callback "Missing credentials" Passport js local strategy custom callback "Missing credentials" express express

Passport js local strategy custom callback "Missing credentials"


How you format the data in HTML form

Here I'm using Postman to demonstrate your issue:

enter image description hereThis is not good

Just the output that I wantJust the output that I want

Not closing with (req, res)

Although this might not be related a bit, but the same problem occurs if I didn't do this.

  1. Invoke req and res parameters before initiating the passport.authenticate
  2. After you close the passport.authenticate, finish it with (req, res)

You need (req, res) at the end of your function, as so:

router.post('/signup', (req, res, next) => passport.authenticate('whatever-your-strategy-name-is', function(err, user, info) {    // Just to see the sample expected output    res.send(JSON.stringify(info)).status(200)  })(req, res));

In standard familiar JS, it looks like this.

router.post('/signup', function (req, res, next) {  passport.authenticate('whatever-your-strategy-name-is', function(err, user, info) {    // Just to see the sample expected output    res.send(JSON.stringify(info)).status(200)  })(req, res) // passport.authenticate ends here})


Just in case this might be useful to someone in the future..If your using POSTMAN and your sending a POST request(of say an email and password field for example) and you find yourself seeing this "missing credentials" response make sure that the format of the response is set to JSON and not like html or text cause a simple mistake like that can get you stuck for hours


I got this error of missing credentials is when i was sending email as a first parameter, but passport local strategy accepts first parameter a UsernameSo you need to set it as email like that :

passport.use(    new LocalStrategy({ usernameField: "email" }, (email, password, done) => {