#How to access cookies inside server function?

1 messages · Page 1 of 1 (latest)

pulsar grail
#

Is there a way to access cookies (or the request) inside a Server Function (RSC mode)? NextJS provides a cookies function always scoped to the request, but all the cookie docs in RR point to accessing the raw request via loader/component props, which we don't get in a server function?

near merlin
#

first, remember RSC support is still unstable/experimental in data mode so there's no full comprehensive content about it on docs

now related to your question, there's no function to access them, you will need to use something like AsyncLocalStorage in your HTTP server and use it to pass the parsed cookies from the request to the server functions

basically you will build this yourself, RR is giving you the tools to use the router with RSC but the rest is up to you

once RSC support is added to framework mode there will most likely be a way to do this

pulsar grail
#

Ok I guess I misunderstood, I thought this was fully cooked but still subject to changes

#

Seems there is also no way to access the raw request/cookies from server components either

near merlin
#

you will need a similar solution using AsyncLocalStorage to pass the request to server components

pulsar grail
#

Ok thanks for the explanation, will just wait until this is fully supported