How to send cookies and headers in app dir
Hello. I have an index page in the pages directory. I want to do the same thing but using the app dir
Basically, I'm sending a request to an express server. Which verifies the user using their access/refresh token gotten from the request cookies/header.
I want to do the same in in appdir. I tried this:
But it doesn't send the cookies/headers to the server.
For context.
fetcher
is just an axios call to get data
3 Replies
from my understanding, you are trying to take the header sent from the client to send to the remote server. If so, you can use the
cookies()
and headers()
methods from next/headers
to get cookies and headers respectively
related docs
https://nextjs.org/docs/app/api-reference/functions/headers#headers
https://nextjs.org/docs/app/api-reference/functions/cookiesNot exactly. So I could access the headers
in the getUser function. My issue now is, I'm trying to send a fetch request to my express server with the headers. But when I send the fetch request, I doesn't have the headers for some reason
I found out the solution