mikenicholson/passport-jwt

Errors like "No auth token" or "invalid signature" end up in info and not error

FBosler opened this issue · 1 comments

when trying to use custom callback like so:

    passport.authenticate("jwt", function (err, user, info) {
        console.log(chalk.red.bold("Called:"), chalk.bold.bgBlue.white('jwtAuthenticateCustomCallback'));
        console.log('err',err)
        console.log('user',user)
        console.log('info',info)
        if (err) {
            console.log(chalk.red(err));
            return res.status(400).json({ errors: err });
        }
        if (!user) {
            console.log(chalk.red(err));
            return res.status(400).json({ errors: "No user found" });
        }
    })(req, res, next);

I am getting the "No auth token" or "invalid signature" in the info argument and not the expected error argument.

See discussion in #160. This is correct behavior, though we should be passing strings and not Error objects to strategy.fail().