Answer the question
In order to leave comments, you need to log in
Why am I not receiving payload?
It seems that I did everything as in the instructions, but I can not log in in any way. I'm trying to enter payload to see why it doesn't find the user, but I only get results from passport.authenticate('jwt') and nothing from the strategy itself. I get a normal token. Then I pass it through postman, but I get an error: "user not found". Passed both through the body in the auth_token option and through the Headers in the Authorization . The user was found, the token was normally created, checked. What am I doing wrong?
Passport.use(new JwtStrategy(jwtOptions, function (payload, done) {
console.log("payload:", payload) // даже не срабатывает
User.findById(payload.id, (err, user) => {
if (err) {
return done(err)
}
if (user) {
done(null, user)
} else {
done(null, false)
}
})
})
);
router.get('/ss', async (ctx, next) => {
await passport.authenticate('jwt', { session: false }, function (err, user) {
if (user) {
ctx.body = "hello " + user.email;
} else {
ctx.body = "No such user";
console.log("err", err) // получаю вывод только здесь
}
} )(ctx, next);
});
Answer the question
In order to leave comments, you need to log in
The problem was that I did not specify what to check when trying to authorize:
const jwtOptions = {
jwtFromRequest: ExtractJwt.fromHeader('authorization')
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question