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 authentication callback not receiving error #248

Open
wlingke opened this issue May 27, 2014 · 0 comments
Open

Custom authentication callback not receiving error #248

wlingke opened this issue May 27, 2014 · 0 comments

Comments

@wlingke
Copy link

wlingke commented May 27, 2014

I am using a local authentication strategy and I am using the custom callback such as so:

router.post('/create_account',
    function (req, res, next) {
        passport.authenticate('local-signup', function (err, user, info) {
            if (err) {
                console.log("error found")
                return next(err);
            }

            //custom callback requires manually creating the session
            req.login(user, function (err) {
                if (err) {
                    return next(err)
                }
                return res.send(200);
            });
        })(req, res, next);
    }
);

However, it seems that if there is an error and I invoke done(error) where error is non-null, in configuration of the strategy, the passport.authenticate's callback never gets called. In other words, I never see the "error found" log. Instead, the error goes straight to my final error handler.

This is how the configuration looks:

passport.use('local-signup', new LocalStrategy({
                usernameField: 'email',
                passwordField: 'password',
                passReqToCallback: true
            },
            function (req, email, password, done) {
                var newUser = new User();
                // save the user
                newUser.save(function (err) {
                    if (err) {
                        //********Assume Error occurs here!*******
                        return done(err)
                    }
                    done(null, newUser);
                });

            })
    );


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

1 participant