How to access session token with next-auth in order to attach it to a API request header?

Viewed 835

Hello I'm new to next js and react. My project currently has a 3rd party api that i'm working with that requires a session token input in the header for all requests.

So I picked Next-Auth for authentication but I have problem accessing that chunk of raw jwt. I tried useSession but it only gives me info within jwt (users, expiration, etc). I found a server side function in documentation called getToken() but the sample requires a line like this:

const secret = process.env.SECRET

Does that mean i need the secret key to the jwt signature in order to retrieve the raw jwt?

I can see that session token in my cookie under my localhost file. I tried to use js-cookie to get() that cookie but I can't get deeper to get the inner cookies.

I wonder how I should approach this problem and what's the proper way to attach session token in api requests for next-auth setup.

Thanks!

0 Answers
Related