Next.js Discord

Discord Forum

Set cookie in the next.js middleware for the client side

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
I need to share a very specific information that runs on the server side using next middleware and then share with the client side this information. I was trying to use the cookies but I had this problem: Error: Cookies can only be modified in a Server Action or Route Handler. next middleware

2 Replies

American black bearOP
this is happening because inside the middleware I have this code: cookies().set(STORAGE_KEYS.AUTH.LOCALE, locale);
American black bearOP
nevermind