Pritam Parua
Pritam Parua

Reputation: 692

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.

Upvotes: 4

Views: 2418

Answers (1)

Daniel Hernandez
Daniel Hernandez

Reputation: 104

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

Upvotes: 9

Related Questions