mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.97k stars 214 forks source link

gracefull json response when no token #71

Closed sergiator closed 8 years ago

sergiator commented 8 years ago

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); });

mikenicholson commented 8 years ago

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.