Skip to content

How can I attach my JWT to every axios call? #3550

Discussion options

You must be logged in to vote

useSession() can only be used for client side. getSession is used for client and server side.

You can make the code you have use async/await:

async (response) => {
      const session = await getSession();
      if (session) {
        request.headers.Authorization = `Bearer ${session.accessToken}`;
      }
      return response;
    },

Replies: 9 comments 50 replies

Comment options

You must be logged in to vote
25 replies
@nirglow
Comment options

@FeMaffezzolli
Comment options

@nik32
Comment options

@IamDieuKhanh2001
Comment options

@whateverneveranywhere
Comment options

Answer selected by balazsorban44
Comment options

You must be logged in to vote
11 replies
@Webbrother
Comment options

@nik32
Comment options

@nik32
Comment options

@IamDieuKhanh2001
Comment options

@diep89
Comment options

Comment options

You must be logged in to vote
8 replies
@neotrow
Comment options

@Webbrother
Comment options

@neotrow
Comment options

@nik32
Comment options

@coder054
Comment options

Comment options

You must be logged in to vote
3 replies
@nik32
Comment options

@modbender
Comment options

@nik32
Comment options

Comment options

You must be logged in to vote
1 reply
@neotrow
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@emreastarcioglu
Comment options

@viniciuslk
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
question Ask how to do something or how something works
Converted from issue

This discussion was converted from issue #3549 on January 01, 2022 18:43.