Allow object to be shown in error callback #35

engram-design opened this Issue Apr 19, 2013 · 5 comments


None yet
2 participants

Just wondering if support could be added for passing an object to the verified() function?

function verified(err, user, info) {
    return (typeof(err) === 'object') ? self.error(JSON.stringify(err)) : self.error(err);
    if (!user) { return; }
    self.success(user, info);

This simple solution would allow for the following in the authenticate() function

authenticate: function(username, pw, done) {
    User.findByName(username, function(err, user) {
        if (err) { return done(err); }
        if (!user) { return done({ error: 'Unknown user ' + username }, false); }
        if (!User.checkPassword(pw, user)) { return done({ error: 'Invalid password' }, false); }
        return done(null, user);

This would allow a more descriptive error message to be displayed, rather than just a true/false.



jaredhanson commented Apr 19, 2013

That's what the third info argument is for. See here for an example:

Does that suit your needs?


jaredhanson commented Apr 19, 2013

Also, see here for more details:

That's exactly what I was doing, but the only output I get is Unauthorized when an error occurs - no sign of the content in the info argument.

Calling the route with'/session', passport.authenticate('local'), function(req, res) {});. Should I be using the callback method instead?


jaredhanson commented Apr 19, 2013

Depends on what your app requires. The redirect options and flash messages which are built in, as that's the typical use case. The callback is used when those don't suite your needs.

@jaredhanson I've thrown together a quick Gist which reproduced the above situation - would you mind verifying what I'm doing is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment