Passport: Documentation for failWithError option

Created on 6 Feb 2016  路  4Comments  路  Source: jaredhanson/passport

I've noticed that the failWithError option was added back in 2014 (see #126) and wasn't documented in the function description.

This is especially important for people that want a custom error message without having to implement a custom callback:

app.post('/login',
  passport.authenticate('local', { failWithError: true }),
  function(req, res, next) {
    // Handle success
    return res.send({ success: true, message: 'Logged in' })
  },
  function(err, req, res, next) {
    // Handle error
    return res.status(401).send({ success: false, message: err })
  }
)

Most helpful comment

+1 for this. It took me a long time to figure out that this is already supported. I also agree that the passport middleware should not end the middleware chain by default.

All 4 comments

+1 just stumbled into this when trying to figure out how to implement custom error messages.

Yup, yup +1 on this as well. Having middleware that executes _after_ responses is a vital pattern. The passport default of killing the middleware chain is kind of a bummer most days.

Duplicate: #364

+1 for this. It took me a long time to figure out that this is already supported. I also agree that the passport middleware should not end the middleware chain by default.

+1 looks like some attempted PRs are stale now, but would love to see this doc change too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wongeun picture wongeun  路  4Comments

ginovski picture ginovski  路  6Comments

scan picture scan  路  7Comments

ksmithut picture ksmithut  路  6Comments

angel1st picture angel1st  路  5Comments