passport-jwt often used side-by-side with passport-local but it has a different approach for handling empty parameters. With this changes you can handle empty token error using next code:
router.get('/protectedRoute', function (req, res, next) {passport.authenticate('jwt', { session: false }, function (err, user, info) {if (err) {return next(err);}if (!user) {return res.status(401).json(info);}// do your stuff here - just return 'user' for examplereturn res.status(200).json(user);})(req, res, next);});
Unit tests are not passing. It doesn't appear that the strategy gracefully handles options.badReqeuestMessage not being set. You can click the details link above to view the error on Travis CI.
passport-jwt often used side-by-side with passport-local but it has a different approach for handling empty parameters. With this changes you can handle empty token error using next code:
router.get('/protectedRoute', function (req, res, next) {
passport.authenticate('jwt', { session: false }, function (err, user, info) {
if (err) {
return next(err);
}
if (!user) {
return res.status(401).json(info);
}
// do your stuff here - just return 'user' for example
return res.status(200).json(user);
})(req, res, next);
});