Next.js Discord

Discord Forum

Why i can't set a cookie from the api?

Unanswered
Mawhadmd posted this in #help-forum
Open in Discord
The problem here is that when i click a button, a server action is invoked, and then the server action calls the api, and the api needs to set a cookie. Now what i don't understand is why am i able to set cookies in server actions and not api? aren't they the same thing (endpoints).

1 Reply

Asian black bear
If your server is calling the external API which sets a cookie it tries to set it for the server. It has no knowledge of the client. Your server code needs to set the cookie for the client based on the API response.