I'm having some problems with Passaport.js.
When I try to run my api, the terminal returns an error. I went in the file in question and did not find anything wrong.
I searched the net, but the solutions I found left the code to what I have now. So I do not know what could be wrong.
The error returned is this:
/var/www/html/express/app/learnapp/auth.js:9
jwtFromRequest: ExtractJwt.fromAuthHeader()
^
TypeError: ExtractJwt.fromAuthHeader is not a function
at Object.<anonymous> (/var/www/html/express/app/learnapp/auth.js:9:30)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/var/www/html/express/app/learnapp/app.js:5:12)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
The code for the auth.js file is this:
var passport = require("passport");
var passportJWT = require("passport-jwt");
var users = require("./users.js");
var cfg = require("./config.js");
var ExtractJwt = passportJWT.ExtractJwt;
var Strategy = passportJWT.Strategy;
var params = {
secretOrKey: cfg.jwtSecret,
jwtFromRequest: ExtractJwt.fromAuthHeader()
};
module.exports = function() {
var strategy = new Strategy(params, function(payload, done) {
var user = users[payload.id] || null;
if (user) {
return done(null, {id: user.id});
} else {
return done(new Error("User not found"), null);
}
});
passport.use(strategy);
return {
initialize: function() {
return passport.initialize();
},
authenticate: function() {
return passport.authenticate("jwt", cfg.jwtSession);
}
};
};