I'm now retired and now have some time to learn how to develop an MEVN application ;-) I'm now in the point of securing a few pages in the app with a jwt
token.
I can log a user and later read its token:
app.get('/movies', (req,res) => {
jwtOptions.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme('jwt');
console.log(Version + 'JWT token: ' + jwtOptions.jwtFromRequest(req));
Movie.find({}, 'name description release_year genre', (error, movies) => {
if(error) { console.log(error);}
console.log(Version + "Fetched " + movies.length + " movies");
res.send(movies);
});
});
I get the user token in the console. Fine! This get request is not yet protected. To protect it I modify slightly the 1st line:
app.get('/movies', passport.authenticate('jwt', { session: false }), (req,res) => {
...
An error is now triggered.
Unknown authentication strategy "jwt"
After reading a few million questions and answers on various sites, I'm short of any idea to fix my problem. Suggestions will be highly appreciated.
Thanks
Did you check your server.js or index.js? you should add some initializer. I received same error and I was missed those
const passport = require('passport');
// Passport middleware
app.use(passport.initialize());
// Passport Config
require('./config/passport')(passport);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With