-
Notifications
You must be signed in to change notification settings - Fork 155
fix(converters): Ensure x-forwarded-proto is set to http when running locally #887
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 68bb9b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
@@ -35,6 +35,12 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = { | |||
), | |||
); | |||
|
|||
// This is to make libraries (e.g. next-auth) that rely on this header to work out of the box in `opennextjs-cloudflare preview`. | |||
// See https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/lib/utils/env.ts#L95-L96 | |||
if (url.protocol.startsWith("http") && url.hostname === "localhost") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
if (url.hostname === "localhost") {
headers["x-forwarded-proto"] = url.protocol;
}
Because wrangler dev --local-protocol=https
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah alright. I was trying to decide if this should go in the converter or wrapper? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ how is this header passed to https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/lib/utils/env.ts#L95-L96
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They use { headers}
from next/headers
inside an action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is again another case where the protocol would default to https
if we don't have a x-forwarded-proto
header set.
I have to dig a bit further on this one. Turns out you might need an |
Im using this repo to test out. First build the repo with However when in // this is for the redirects to work with http
process.env.__NEXT_PRIVATE_ORIGIN = url.origin;
// this makes the signin button redirect to http
headers["x-forwarded-proto"] = "http"; Remember to change the overrides path in Notice the |
Alright, this one was a bit harder to debug than I initially thought. Turns out this is related to
There is some workarounds (
To see this yourself you can just add an API route in your app and run OpenNext locally either via import { NextRequest } from "next/server";
export async function GET(request: NextRequest) {
return Response.json({
// when running OpenNext locally this url with https when it should not
url: request.url,
})
} |
Discussed in #686 over at
opennextjs-cloudflare
next-auth
and possibly more libraries rely on thex-forwarded-proto
header to behttp
to work out of the box when run locally. Innext start
ornext dev
they set this tohttp
when ran locally.To make
opennextjs-cloudflarejs preview
and our node converter when running OpenNext locally behave the same we would want to set this header tohttp
. This would make the user not have to set anAUTH_URL
in those modes.