Next.js Discord

Discord Forum

Fetching data in server Component

Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
Original message was deleted.

12 Replies

No, you should separate the logic and import it for both api route and server component: https://nextjs-discord-common-questions.joulev.dev/fetching-own-api-endpoint-in-react-server-components
you can use cookies in server component
but i don't see how calling the api in server component will solve you issues... as the cookies won't be parsed
does this function get run on root page?
thats why... you are redirecting infinitly...
as if no token, redirect
and as the error suggests, the cookie isn't removed and instead redirected
what are you trying to do on the client?
logout?
you should use middlewire for this tbh
yeah, you see the pathname and cookies and can redirect accoudingly
and it makes the code easier to understand