T
T
teodor7teodor72019-12-07 13:45:45
Node.js
teodor7teodor7, 2019-12-07 13:45:45

How to get a JWT string in passport-jwt?

I use Express.js, Passport.js., jsonwebtoken I save
the JWT token to the database, then I want to check it from Bearer.
JwtStrategy allows you to perpetuate and get the jwtPayload object. But I need to get the encrypted string. The documentation says rawJwt, but how to get the raw string itself in order to compare it in the database? How to extract correctly?

passport.use(new JwtStrategy({
          jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
          secretOrKey   : config.secretOrKey
      },
      function (jwtPayload, cb) {
          return User.find({_id: jwtPayload.user._id, token: token})// сравниваем токен который идет в зашифрованном виде
              .then(user => {
                  return cb(null, user);
              })
              .catch(err => {
                  return cb(err);
              });
      }
  ));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question