Skip to content

feat: add multiple set-cookie headers in middleware #1970

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

Merged
merged 6 commits into from
Mar 7, 2023
Merged

Conversation

sarahetter
Copy link

Summary

Fixes an issue where Deno Headers.set overwrites the previously set header, instead of adding a new set-cookie header. This means that we only ever had one set-cookie header, which was always the most recently added cookie.

You are supposed to set multiple set-cookie headers, one per cookie (not a string of multiple cookies in one header). Deno's PR to add the ability to add multiple set-cookie headers uses the append method. See example in their test files for the PR.

I removed @taty2010 's work to do with adding originCookies , as it turned out not to be required - the origin set-cookie headers were already present in the response object, but because we were doing response.headers.set(key, value) with a middleware set-cookie header, it removed all of the origin set-cookie headers and replaced them with the last-executed middleware set-cookie header. This PR is tested by the original tests in Taty's original PR.

This PR also solves an issue where you were only able to set one cookie in your middleware file, which we thought was a feature but was actually a bug 🐛 😅

Test plan

  1. Add more than one response.cookies.set('something', 'myvalue) to a middleware.ts file
  2. Add a cookie on a page in next.js
  3. Validate that all set-cookie headers (multiple from middleware, one from origin) are present on the response.

Related: https://github.com/netlify/pillar-support/issues/306

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@sarahetter sarahetter requested a review from a team March 6, 2023 21:18
@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/64074f64590e6f0007abd947
😎 Deploy Preview https://deploy-preview-1970--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/64074f6450b16700084d13b0
😎 Deploy Preview https://deploy-preview-1970--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/64074f64f0a58f0008762719
😎 Deploy Preview https://deploy-preview-1970--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Mar 6, 2023
@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/64074f64e7f5600008fb34f1
😎 Deploy Preview https://deploy-preview-1970--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/64074f64769c10000926aecd
😎 Deploy Preview https://deploy-preview-1970--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/64074f64db22ce000882cf2a
😎 Deploy Preview https://deploy-preview-1970--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/64074f640356b0000858208c
😎 Deploy Preview https://deploy-preview-1970--next-plugin-canary.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/64074f64205c2000088d166d
😎 Deploy Preview https://deploy-preview-1970--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 6, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 25be882
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/64074f64af289b0008c027b1
😎 Deploy Preview https://deploy-preview-1970--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@taty2010 taty2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@MarcL MarcL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick debugging on this, @sarahetter! 🎉
:shipit: (but added the comment on the code as I've just thought about it!)

@kodiakhq kodiakhq bot merged commit 32b31c6 into main Mar 7, 2023
@kodiakhq kodiakhq bot deleted the cookie-behaviour branch March 7, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants