-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Setting multiple Set-Cookie
headers using the vercel adapter
#9221
Comments
Not sure how to solve this one. The Fetch API doesn't allow setting multiple headers with the same name. They always get concatenated when using |
Yes, I saw that as well. It's just weird to me that it's working for some platforms, and it's not for others. Maybe whatever workaround the Netlify adapter is using the Vercel adapter could implement as well, given that it's actually the adapters responsible for this behavior. I'm aware that we can't change platform internals :D |
Oh neat! Just saw how it’s done in the netlify adapter. Link |
This 'works' on Vercel too, as long as you're using serverless functions, because we do this: kit/packages/kit/src/exports/node/index.js Lines 110 to 116 in 557422b
(The same applies to any platform that uses the Node Some background: Unfortunately, the Back to the issue at hand. The behaviour we see on Netlify (and Vercel, when using serverless functions) isn't actually correct in this case. It's designed to handle this situation... headers = new Headers();
headers.append('Set-Cookie', 'a=1');
headers.append('Set-Cookie', 'b=2'); ...by splitting headers = new Headers();
headers.set('Set-Cookie', 'a=1, b=2'); And here's where we get to the crux of the matter: unfortunately, your code is wrong. If you're using TypeScript, it'll even tell you your code is wrong: But web APIs are forgiving, and instead of throwing an error it will simply coerce the array to a string: String(array) === array.join(','); Happily, it's easy to fix your code — just create a So: the correct behaviour here isn't for this to work on Vercel edge functions, it's for it to fail on Vercel serverless functions and Netlify. We'll be able to make that change very soon, as This is a semver quandary though — if people are relying on the buggy behaviour, is the fix a breaking change? |
Describe the bug
It seems like it's not possible to set more than one cookie in an Vercel endpoint using the
Set-Cookie
header. Similar to the bug described in #3460, the cookies get concatenated, even though this will lead to most browsers only recognizing the first cookie set (According to MDN, multiple cookies should be set using multipleSet-Cookie
headers instead of concatenating them in one).The issue mentioned above already describes multiple workaround like creating a separate
Headers
orResponse
object and adding the different cookie headers using theappend
function, but this doesn't seem to fix this issue for the Vercel adapter. Deploying exactly the different code on other platforms like Netlify resolves this issue for me.Reproduction
Deploying an endpoint on Vercel, and trying to set multiple cookies in the header:
Logs
No response
System Info
Whatever system environment the serverless functions of Vercel are using. Adapter version: `@sveltejs/[email protected]`
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: