Answer the question
In order to leave comments, you need to log in
How to pass authorization token from cookie's to header?
When a user logs in, I have a JWT token created and signed. After that, it is recorded in cookies. Further, when visiting the page, the user should check the token. But how to get the token from the cookie and pass it to the application?
koa is used.
For authorization koa-passport and jwt scheme.
router.get('/test', async(ctx,next) => {
await passport.authenticate('jwt', function(err, user) {
if (user == false) {
ctx.body = {title: "Auth", message:"Error of auth", err: err}
} else {
ctx.body = {title: 'Auth', message:`Congrutilations! Welcome to SunSpark ${user.email}`}
}
})(ctx, next)
});
Answer the question
In order to leave comments, you need to log in
https://www.npmjs.com/package/koa-cookie
www.passportjs.org/packages/passport-jwt/#extracti...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question