accessing jwt token when using next-auth
Unanswered
Cuban Crocodile posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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](https://cdn.discordapp.com/embed/avatars/0.png)
Cuban CrocodileOP
seems like this is the way to go
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
can you send
async jwt
function![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
and what if you log
account.token or account.access_token
, check first what account returns![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Cuban CrocodileOP
undefined
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
which provider are you using?
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Cuban CrocodileOP
credential
CredentialsProvider
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
so I believe that you're integrating this into the existing database, where you have some users already saved
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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](https://cdn.discordapp.com/embed/avatars/2.png)
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