Conditionally using cookies() if fetch utility is called in a server component
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hey folks, I have a function
doFetch wrapping fetch that all of my api requests go through. I'm using app router and authentication is done with cookies (stored in the browser) so when I call doFetch in a server component the cookies aren't available and the request returns a 401. I can see the cookie I need if I use the cookies hook, but I get an error if I import that hook in a function called from a client component. The doFetch wrapper is called from both client and server side components. How can I pass cookies along with my api calls made from server components? Do I need to create a totally separate function to make fetch requests from server components?