How to Get the JWT Token Using NextAuth?

0
13
Asked By CuriousCoder42 On

I'm currently using NextAuth version 5.0.0-beta.29 in my project, and I'm trying to extract the JWT session token to use it in Bruno (an API testing app) for my request header. I've spent hours looking for the right way and finally tried using `getToken(req, secret, { raw: true })`. Although I managed to get the token, when I pasted it into Bruno, I still encountered a "not authenticated" error. I also tested with curl and got the same result. How do I correctly retrieve and use the JWT token with NextAuth when performing API testing?

1 Answer

Answered By TechieTina88 On

I totally understand your struggle with NextAuth and retrieving the raw JWT for testing in Bruno! I had the same issue and figured out it was due to my API route not properly verifying the token. I also used `getToken({ req, secret, raw: true })`, but it didn't work until I ensured my server was actually checking the `Authorization` header for the JWT. Make sure your setup correctly reads and decodes the token; that could solve your issue!

DevDude99 -

Can you share how your API route is set up? I'm building a simple API for testing and still running into the "not authenticated" error.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.