Cookies in Server Action
Answered
Masai Lion posted this in #help-forum
Masai LionOP
I have a server action that calls a backend endpoint and it returns with set-cookie to set the cookie. The problem is since it is in server action, it is not being set the the client. I do not really want to setup API route and do not want to call the api directly from client as well. How do i pass the cookie to the client or is it even possible?
Answered by B33fb0n3
... and do not want to call the api directly from client ...why not?
A server actions is also just a route handler, that is defined by nextjs (technically)
5 Replies
... and do not want to call the api directly from client ...why not?
A server actions is also just a route handler, that is defined by nextjs (technically)
Answer
you can use rewrites to allow nextjs to be a proxy server and have set cookie, OR you can in server action get response of fetch and get the set-cookie header and then use cookies().set(...) in server action
@Masai Lion solved?
Masai LionOP
Yes, thank you