Easiest Way to Get and Use JWT Tokens for API Calls?
Unanswered
Wombo posted this in #help-forum
WomboOP
Hey everyone, what's the easiest way to get a JWT token so I can set it as an Authorization header? I want to make an API call to the backend from the client to get some data. I need to use search parameters, filters, etc.
Right now, my only idea is to call an API route from the browser, and this route will call the backend with parameters from the browser + token from getToken({req}) in 'next-auth/jwt', essentially working as a proxy. It sounds unnecessarily complicated, as I have to write the same code twice - once for the client and once for the API route.
Is there a better way?
I'm using Next 14 and NextAuth 4
Right now, my only idea is to call an API route from the browser, and this route will call the backend with parameters from the browser + token from getToken({req}) in 'next-auth/jwt', essentially working as a proxy. It sounds unnecessarily complicated, as I have to write the same code twice - once for the client and once for the API route.
Is there a better way?
I'm using Next 14 and NextAuth 4