Next.js Discord

Discord Forum

cookies()

Answered
Southeastern blueberry bee posted this in #help-forum
Open in Discord
Southeastern blueberry beeOP
hey
can i pass cookie value from server component to client component as props ?
Answered by MikeTheTechLead
One little tidbit: Page generation becomes dynamic (as in per request) if you do.
Otherwise, if the cookie is NOT http-only, you can instead grab it out in the client component directly and make sure its only client rendered. This way you can keep the page statically rendered
View full answer

9 Replies

@Southeastern blueberry bee what else do u need?
Southeastern blueberry beeOP
Nothing else thanks for your help
One little tidbit: Page generation becomes dynamic (as in per request) if you do.
Otherwise, if the cookie is NOT http-only, you can instead grab it out in the client component directly and make sure its only client rendered. This way you can keep the page statically rendered
Answer
@B33fb0n3 he can also add export const dynamic = 'force-static' on top of his page and the page will be statically rendered. Btw: that wasnt his question 🙂
But then the cookies function will become empty 🙂

What i was getting at was that getting cookies on the server to then pass it to a client component seems a little hacky / wrong to me, and seems to be a way to circumvent a http-only cookie, which is supposed to NOT be accessible in javascript because it can be exploited
But in this case im thinking on stuff like jwt / session cookie or similar