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

🐛 BUG: Unable to set multiple cookies #3024

Closed
1 task
thepassle opened this issue Apr 7, 2022 · 6 comments · Fixed by #3026 or #3092
Closed
1 task

🐛 BUG: Unable to set multiple cookies #3024

thepassle opened this issue Apr 7, 2022 · 6 comments · Fixed by #3026 or #3092
Assignees

Comments

@thepassle
Copy link
Contributor

What version of astro are you using?

1.0.0-beta.2

What package manager are you using?

npm

What operating system are you using?

mac

Describe the Bug

It seems like only one cookie is being set, consider the following code:

export function get() {
  const headers = new Headers();
  headers.append('Set-Cookie', `foo=foo; HttpOnly`);
  headers.append('Set-Cookie', `bar=bar; HttpOnly`);

  console.log(headers); //  {'set-cookie': [ 'foo=foo; HttpOnly', 'bar=bar; HttpOnly' ]}

  return new Response('', {
    status: 201,
    headers,
  });
}

Only one cookie actually makes it to the browser:

image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-v7wdzd?file=src/pages/foo.js

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp self-assigned this Apr 7, 2022
@matthewp
Copy link
Contributor

matthewp commented Apr 7, 2022

Bug in the dev server, we need to use this to allow multiple of the same header: https://nodejs.org/api/http.html#responsesetheadername-value

@matthewp
Copy link
Contributor

matthewp commented Apr 7, 2022

This is apparent a problem with the fetch standard :/. Think there is probably a workaround though.

@thepassle
Copy link
Contributor Author

Oh really? Thats interesting. Do you have a link or anything? Just for my curiosity

@matthewp
Copy link
Contributor

matthewp commented Apr 7, 2022

here's one such: whatwg/fetch#973

There's not a method on Headers to get all of the headers. calling .append() results in concatenating the headers, comma-separated. Set-Cookie is the exception which cannot be done this way.

The reason you see it correctly in your console.log is because node-fetch (which we are using for this) has a special headers.raw() method which is what I'm going to use.

@thepassle
Copy link
Contributor Author

thepassle commented Apr 12, 2022

This fix worked for me during local development, however I'm now seeing it again I deploy my app on Netlify:

image

image

Only the first cookie ever seems to get set

@matthewp
Copy link
Contributor

Reopening to fix the Netlify adapter bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants