Next.js Discord

Discord Forum

Fetch data in client side

Unanswered
(-.-) posted this in #help-forum
Open in Discord
Avatar
(-.-)OP
I'm using Next.js 14 and have the following situation: when opening a modal, I need to make a call to the backend to fetch some data. However, in this call, I have to pass the JWT token, which is only accessible on the server side. How can I make this call when opening the modal on the client? How do you handle these calls?

3 Replies

Avatar
(-.-)OP
I thought about using "use server", but it would break the semantics of actions, because that would be a get call
the solution I did was to create a route handler, when opening the modal I call my handler api and this api calls my Backend passing the jwt. Would it be a good solution? For me this works.
Avatar
Ray
yes but keep in mind that GET endpoint is static by default. use route segment config to adjust to your need