Skip to content

Server Component calling server action getting Cookies can only be modified in a Server Action or Route Handler. error #60025

Answered by ananuness
the-devbear asked this question in Help
Discussion options

You must be logged in to vote

This means is that you cannot support this behavior with just Server Components, you need to use either:

  • An API call that sets the cookie
  • Set the cookie in JS in the browser
  • Use Server Actions
  • Use middleware

You have those 4 ways to archive it without problems, you can see more about it in this article.

Also, Server actions are used to handle form submissions and mutations, but it's not limited to it, you can invoke it in event handlers, like useEffect for example. See more about Server Actions and its behavior here.

Finally, as you can see you're just calling it directly in your Server component, that's why you got the error. Now, taking into account what was said, to make your work ea…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@ananuness
Comment options

@seydanurhatipoglu
Comment options

@Juanryhn
Comment options

@Housi
Comment options

@tstiemerling
Comment options

Answer selected by the-devbear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
6 participants