Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEXT-645] Calling cookies.set twice sets only one value, in appdir route.ts #46355

Closed
1 task done
raphaelbadia opened this issue Feb 24, 2023 · 8 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@raphaelbadia
Copy link
Contributor

raphaelbadia commented Feb 24, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020
Binaries:
Node: 16.16.0
npm: 9.1.2
Yarn: 1.22.19
pnpm: 7.23.0
Relevant packages:
next: 13.2.1
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/raphaelbadia/next-set-two-cookies-appdir-route

To Reproduce

clone the repository, run it, open the route /api (http://localhost:3000/api) , check the Network tab for the "cookie" request.

Describe the Bug

Calling "cookies.set" twice on an appdir api route will set only one cookie.

CleanShot 2023-02-24 at 11 16 46@2x

Expected Behavior

You'll see one "Set-Cookie" with 2 values, however it should be instead 2 "Set-Cookie" with only one value.

Set-Cookie can be repeated as many time as needed in an HTTP response to set multiple cookies.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-645

@raphaelbadia raphaelbadia added the bug Issue was opened via the bug report template. label Feb 24, 2023
@raphaelbadia
Copy link
Contributor Author

It is very much like #38302 , but in regular nodejs api route

@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label Feb 27, 2023
@timneutkens timneutkens changed the title Calling cookies.set twice sets only one value, in appdir route.ts [NEXT-645] Calling cookies.set twice sets only one value, in appdir route.ts Feb 27, 2023
@PHILLIPS71
Copy link

I've been running into the issue also and after doing some digging it's due to the set-cookie headers being appended, according to the Headers.append() method's documentation it states;

The append() method of the Headers interface appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist.

It's seems it's what's happening in this case here, calling append multiple times on a set-cookie header will append the new value as a comma separated string instead of adding an additional header.

The issues actually resides in https://github.com/vercel/edge-runtime at https://github.com/vercel/edge-runtime/blob/main/packages/cookies/src/response-cookies.ts#LL96

@benderillo
Copy link

benderillo commented Mar 3, 2023

I wonder if this issue being worked on. It currently blocks the work in NextAuth repo to support Route Handlers.

@raphaelbadia
Copy link
Contributor Author

@timneutkens thanks for taking a look into the issue, but it's not fixed in the latest 13.2.4 😔 Please reopen it

@ManuelJustMobileSec
Copy link

+1 this is still happening. In my backend, I'm sending back to Next more than one set-cookie header and only the first one is being set.

@timneutkens
Copy link
Member

Duplicate of #46579

@timneutkens timneutkens marked this as a duplicate of #46579 Mar 20, 2023
@artemavrin
Copy link

I just checked
In middleware setting 2 cookies works as it should, but in app/route, it sets only the first value

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

No branches or pull requests

6 participants