Next.js Discord

Discord Forum

how to handle data fetching on server vs client side with cookies

Unanswered
Common Moorhen posted this in #help-forum
Open in Discord
Common MoorhenOP
when building services to fetch data on my next JS project, I often find myself building conditionals for adding cookies on the headers or not.

because the request can be performed from a client or server component, and depending on whether I can need the cookie header or don't.

I was thinking of building my own function that checks for window type and based on that gets the cookie and adds it to the headers, but I don't want to reinvent the wheel.

is there any standard solution for this? I guess is a problem devs would face frequently enough, so I imagine there would be a solution already built, or a standard way to do it.

3 Replies