mikenicholson/passport-jwt

authenticate callback function parameters

gkatsanos opened this issue · 0 comments

I was wondering if the following is correct:
router.get(validate.authorization, authorize(), controller.list);

const handleJWT = (req, res, next) => async (err, user, info) => {
  const error = err || info;

  if (err || !user) {
    Boom.boomify(error, { statusCode: 401, stack: err ? err.stack : 'null' });
    return next(error);
  }

  req.user = user;

  return next();
};

exports.authorize = () => (req, res, next) =>
  passport.authenticate("jwt", { session: false }, handleJWT(req, res, next))(
    req,
    res,
    next
  );

It seems the handleJWT is not getting all parameters under some scenarios and by reading at the documentation wasn't sure if what I'm doing is correct.