Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to render form on failure #2

Closed
mwawrusch opened this issue Jan 6, 2012 · 4 comments
Closed

How to render form on failure #2

mwawrusch opened this issue Jan 6, 2012 · 4 comments

Comments

@mwawrusch
Copy link

Hi Jared,

I need to render a form on login failure showing an error. What is the most elegant way to do that with password?

@thatmarvin
Copy link

I was wondering the same thing. The first example in http://passportjs.org/guide/authenticate.html mentions that Passport returns a 401 Unauthorized, but I don't see a way to do something like rendering a login form. A callback might be useful here?

In the next example, it looks like POSTing to /login with invalid credentials yields a HTTP 302 back to /login. In HTTP speak, the response is saying "/login is temporarily available in /login", which doesn't make sense. Practically speaking, the original POST data (username, password etc) is now lost since the page you now see is a new GET request to /login.

A 401 Unauthorized is the appropriate response in this case ("what you sent to /login is invalid"), but that means that the interface failureRedirect would no longer make sense. Again, maybe a failure callback instead?

@525c1e21-bd67-4735-ac99-b4b0e5262290

bump

@jaredhanson
Copy link
Owner

Linking to passport #3, which has relevant discussion on this topic.

@jaredhanson
Copy link
Owner

A failWithError option has been implemented. It can be used to address this issue as follows:

app.post('/login',
  passport.authenticate('local', { successRedirect: '/home', failWithError: true }),
  function(err, req, res, next) {
    // handle error
    return res.render('login-form');
  }
);

For further details, see this comment on issue #126.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants