Next.js Discord

Discord Forum

accessing jwt token when using next-auth

Unanswered
Cuban Crocodile posted this in #help-forum
Open in Discord
Avatar
Cuban CrocodileOP
I am using next auth but i am unable to access the jwt token, i want to token on client and server side both

20 Replies

Avatar
Cuban CrocodileOP
seems like this is the way to go
Avatar
Cape horse mackerel
Avatar
Cuban CrocodileOP
but im am not getting the token within these callbacks
@Cape horse mackerel I am not getting the token within these callbacks
Avatar
Cape horse mackerel
can you send async jwt function
Avatar
Cuban CrocodileOP
async jwt({ token, account, profile }) {
            console.log(token, 'jwt token')
            return token
        },
{ iat: 1695673515,
  exp: 1698265515,
  jti: '003d6ee6-26be-4744-9692-a2563495e8d7'
} 
this is the object i am getting
Avatar
Cape horse mackerel
and what if you log account.token or account.access_token, check first what account returns
Avatar
Cuban CrocodileOP
undefined
Avatar
Cape horse mackerel
which provider are you using?
Avatar
Cuban CrocodileOP
credential
CredentialsProvider
Avatar
Cape horse mackerel
so I believe that you're integrating this into the existing database, where you have some users already saved
Avatar
Cuban CrocodileOP
@Cape horse mackerel No i have a backend already written and hosted i am making an api call to my backend and then getting a token from there
i am providing jwt secrets being used on that backend though
my intenion is to consume those api and that require authetication header being sent to api backend
Avatar
Cape horse mackerel
there is an async authorize function within CredentialsProvider. So within that function you should make an API call and fetch the user data