accessing jwt token when using next-auth
Unanswered
Cuban Crocodile posted this in #help-forum
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
Cuban CrocodileOP
seems like this is the way to go
Cape horse mackerel
Cuban CrocodileOP
but im am not getting the token within these callbacks
@Cape horse mackerel I am not getting the token within these callbacks
Cape horse mackerel
can you send
async jwt
functionCuban 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
Cape horse mackerel
and what if you log
account.token or account.access_token
, check first what account returnsCuban CrocodileOP
undefined
Cape horse mackerel
which provider are you using?
Cuban CrocodileOP
credential
CredentialsProvider
Cape horse mackerel
so I believe that you're integrating this into the existing database, where you have some users already saved
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
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