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

Custom Authenticate Callback Not Called on Error #186

Closed
funseiki opened this issue Nov 28, 2013 · 2 comments
Closed

Custom Authenticate Callback Not Called on Error #186

funseiki opened this issue Nov 28, 2013 · 2 comments

Comments

@funseiki
Copy link

I posted this on Stackoverflow, but thought I might have more luck here:

I was hoping to utilize the custom callback to handle both successes and failures for logins in Passport's authenticate local strategy, but it looks like it's only called on success.

Here is a snippet of what I'm talking about:

passport.use(new LocalStrategy(
    {usernameField: 'email', passwordField: 'password'},
    function(email, password, done) {
        if(canLogin) done(null, user);
        else done({message: "This is an error message" }, false, { message: "Some Info" });
    }
));


app.post('/login', function(req, res, next) {
      passport.authenticate('local', function(err, user, info) {
         // Only called if err is not set
         res.send("Hello");
    });

From the client, using a bad input:

> curl -d "username=bad&password=input" "http://myurl"
Returns
> [Object object]

A 'good' input returns "Hello."

The docs imply that passport.authenticate allows the error object to trickle down and be handled by the callback, but the above shows otherwise. Am I interpreting this incorrectly?

@jaredhanson
Copy link
Owner

Fixed by commit 4a8230c. This will be released in passport 0.2.0.

@funseiki
Copy link
Author

Great, thanks for the fix!

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

2 participants