Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sailsjs jwt token based authentication example

I am following this Tutorial.

But when i do sails lift to run my application, i am getting below error.

throw new TypeError('JwtStrategy requires a function to retrieve jwt from requests (see option jwtFromRequest)');
^

TypeError: JwtStrategy requires a function to retrieve jwt from requests (see option jwtFromRequest)

Please help me how to solve this error.

like image 764
Pritam Parua Avatar asked Jan 07 '23 15:01

Pritam Parua


1 Answers

The problem is in the configuration of the options for the JwtStrategy, according to the github page, it's missing one option, jwtFromRequest, you need to use an extractor provided with the passport-jwt.

These are my modifications:

var ExtractJwt = require('passport-jwt').ExtractJwt;
var JWT_STRATEGY_CONFIG = {
  jwtFromRequest: ExtractJwt.fromAuthHeader(),
  secretOrKey: SECRET,
  issuer : ISSUER,
  audience: AUDIENCE,
  passReqToCallback: false
};

I hope it help you

like image 73
Daniel Hernandez Avatar answered Jan 14 '23 17:01

Daniel Hernandez