A
A
AlkesPro2020-08-14 13:42:29
JavaScript
AlkesPro, 2020-08-14 13:42:29

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)
});


The whole problem is that I can only pass the authorization check if I manually change the request header and add the header:
authorization: JWT token

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-08-14
@AlkesPro

https://www.npmjs.com/package/koa-cookie
www.passportjs.org/packages/passport-jwt/#extracti...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question