You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a middleware.ts and attach a cookie to the NextResponse
Create a server action, create a cookie and redirect the user
nextjs-bug-server-action-cookie-middleware.mp4
Current vs. Expected behavior
In dev mode :
I would like to set a cookie A from Server Action and a cookie B from the middleware.ts.
I found that if only set a cookie A from Server Action without doing anything into middleware.ts it works well.
Unfortunately, if I also set a cookie B inside the middleware, only the cookie B from the middleware is sent to the browser.
I expect that both cookie A and B are sent to the browser
Any cookie set on a server action is overridden if a cookie is set on the middleware. Additionally, any cookies set on server actions are not available in the response.cookies
Link to the code that reproduces this issue
https://github.com/padupuy/nextjs-server-action-cookies-middleware-bug
To Reproduce
In dev mode :
nextjs-bug-server-action-cookie-middleware.mp4
Current vs. Expected behavior
In dev mode :
I would like to set a cookie A from Server Action and a cookie B from the middleware.ts.
I found that if only set a cookie A from Server Action without doing anything into middleware.ts it works well.
Unfortunately, if I also set a cookie B inside the middleware, only the cookie B from the middleware is sent to the browser.
I expect that both cookie A and B are sent to the browser
In the live example, the bug is not present : https://nextjs-server-action-cookies-middleware-bug.vercel.app/
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:28:58 PST 2023; root:xnu-10002.81.5~7/RELEASE_X86_64 Binaries: Node: 20.9.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 14.1.3 eslint-config-next: 14.1.3 react: 18.2.0 react-dom: 18.2.0 typescript: 5.4.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Middleware / Edge (API routes, runtime)
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: