I'm having trouble setting a server-side cookie
Answered
CodigoK 401 posted this in #help-forum
I did a little test to really see the problem and I still don't understand why it doesn't set the cookie. I tried with axios and fetch and so far there is no different result.
Answered by Asian black bear
Because your server-side page performs the fetch and the
Set-Cookie
instruction is received on the server. The client is not involved in that at all.2 Replies
Asian black bear
Because your server-side page performs the fetch and the
Set-Cookie
instruction is received on the server. The client is not involved in that at all.Answer
You opened a thread with the same issue before, and I think we’ve already covered it: you can’t set cookies from within a server context, you need to do it either inside a Route Handler (like you did) or a Server Action, but you need to call it from the Client.
https://nextjs-forum.com/post/1348857577252847737#message-1348871980090396734
https://nextjs-forum.com/post/1348857577252847737#message-1348871980090396734