我有一个正在尝试调试的函数,因为我收到错误。我已经解决了这个问题,因为我发现有人有类似的问题,但是能够控制台记录 JwtStrategy 中的参数之一确实很有帮助,并且让我更好地理解正在传递的内容。尽管其他人已经能够使用 Postman 及其源代码,但我似乎仍然无法安慰它。
所以我有 mongod 和 nodemon 在后面运行。我这就是函数。
module.exports = function(passport){
let opts = {}; //options is an object literal containing options to control how token is extracted.
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt")
opts.secretOrKey = config.secret; //string containing the secret or pem encoded public key verifying the tokens signiture
passport.use(new JwtStrategy(opts, (jwt_payload,done)=>{
console.log(jwt_payload);
User.getUserById(jwt_payload._doc._id, (err, user)=>{
if(err){
return done(err,false);
}
if(user){
return done(null, user);
}else{
return done(null,done);
}
});
}));
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我有一个 console.log(jwt_payload); 这是我放入 Postman Post 方法http://localhost:3000/users/authenticate 的内容: …