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