I am trying to make a MEAN Stack (Nodejs,Mongo,Angular app) and right now I am trying to make the API Authentication and Token. I am following this tutorial https://www.youtube.com/watch?v=6pdFXmTfkeE&t=185s and my passport.js look like that right now:
passport.js
const JwtStrategy = require('passport-jwt').Stategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require('../models/user');
const config = require('../config/database');
module.exports = function (passport) {
let opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
User.getUserById(jwt_payload.data._id, (err, user) => {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
}
});
}));
}
I am receiving the next error :
TypeError: JwtStrategy is not a constructor at module.exports (C:\Users\dan.diaconu\MakeIT\api\config\passport.js:10:18) at Object. (C:\Users\dan.diaconu\MakeIT\api\app.js:28:29) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3
Any ideas please ? Thank you! :)
const { Strategy:JwtStrategy, ExtractJwt} = require('passport-jwt');
instead of:const JwtStrategy = require('passport-jwt').Stategy; const ExtractJwt = require('passport-jwt').ExtractJwt;
– Zeeshan Hassan Memon