mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.96k stars 213 forks source link

authenticate callback function parameters #212

Open gkatsanos opened 4 years ago

gkatsanos commented 4 years ago

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.