-
Notifications
You must be signed in to change notification settings - Fork 44
Order of headers in Response from middleware differs from vanilla implementation #606
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
Comments
Could you please include a minimal repro (link to a GH repository) with instructions on how to reproduce. |
See https://github.com/NickCrews/next-auth-example/tree/cloudflare-nextauth-header-repro. The steps are in the readme. |
OpenNext actually gives you more flexibility on this one than default Next, you can actually choose on a per-request basis which headers/cookies takes precedence between the middleware and the handler. With default Next you're stuck with whatever Next/Vercel decides for you. We should probably add some docs around this. Just change your import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";
import type { OpenNextConfig } from "@opennextjs/cloudflare/config";
const config = defineCloudflareConfig();
export default{
...config,
dangerous: {
// This one would do the trick for you for example
// You could also always return "handler"
headersAndCookiesPriority(event) {
if(event.method === "POST" && event.headers['next-action']) {
return "handler";
}
return "middleware"
},
} satisfies OpenNextConfig |
Thanks @conico974, that is an excellent workaround. I am curious if we can make the default |
Cloudflare uses the aws adapter under the hood. It was implemented a while back, and the main reason it is this way is to allow to override some headers that Next set (and does/did not allow to override). And as you mentionned, doing what auth.js is not exactly great or recommended. |
Describe the bug
Thank you for your help! I am excited to migrate my app to cloudflare.
See nextauthjs/next-auth#12909
Basically, the cloudflare runtime returns the two
set-cookie
headers in a different order than in vanilla next (eg withnext dev
or when deployed to vercel). This leads to the logout behavior being broken on cloudflare for any app that uses authjs.Now, I don't think this is REALLY your problem. authjs should only be returning a single set-cookie header. But, you are stuck with the result, and there are probably many other libraries out there that are doing this incorrect behavior (returning multiple set-cookie headers with the same name), and all of their users are probably used to them working on eg vercel. So unfortunately, if you want users to be happy to switch from vercel to cloudflare, you could consider
Steps to reproduce
See linked issue
Expected behavior
The headers to be returned in the same order as in vanilla.
@opennextjs/cloudflare version
1.0.0-beta.3
Wrangler version
4.13.2
next info output
Additional context
No response
The text was updated successfully, but these errors were encountered: