Softalent Softalent - 1 year ago 135
Node.js Question

passport jwt verify callback not called

I'm using passport-jwt package for simple authentication and the token is generated by jsonwebtoken.
But the problem is that verify callback is never called.

Here my passport.js code.

var JwtStrategy = require('passport-jwt').Strategy;
var User = require('../app/models/user');
var config = require('../config/database');
var opts = {};
opts.jwtFromRequest = function(req) {
var token = null;
if (req && req.headers) {
token = req.headers.authorization;
return token;
opts.secretOrKey = config.secret;
module.exports = function(passport) {
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
User.findOne({_id: jwt_payload._doc._id}, function(err, user) {
if (err) {
return done(err, false);
if (user) {
done(null, user);
} else {
done(null, false);


Hope to hear from you.


Answer Source

The problem is that you should add 'JWT '(JWT and a space ahead of the original jwt signed). Please check this tutorial by Joshua for assistance. By the way, make sure that if you need a 'where' inside your findOne or not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download