Cookies can only be modified in a Server Action or Route Handler
Answered
French Lop posted this in #help-forum
French LopOP
I've read the provided documentation, but I'm unable to resolve the issue at hand. In a
page.tsx file, I'm trying to set a cookie using ReadonlyRequestCookies.set method, which I assume works by using a [Set-Cookie header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie).Answered by Giant panda
The error is self-explanatory. You cannot set cookies in page files.
6 Replies
French LopOP
I'm prividing this for additional context
Giant panda
The error is self-explanatory. You cannot set cookies in page files.
Answer
French LopOP
what'd be the correct course of action? To resort to Route handler?
Giant panda
Using server actions or route handlers, yes.
French LopOP
thanks
French LopOP
If I wish to set-cookie and also display a page, am I expected to do it with a redirect, or is there a way to return a page with a Route handler?