Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(preview): Ensure the protocol is correct in redirects from server actions during preview mode #689

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 3 commits into from
Jun 2, 2025

Conversation

sommeeeer
Copy link
Contributor

@sommeeeer sommeeeer commented May 29, 2025

Closes #686.

Important to note this didn't only affect next-auth. All redirects from server actions was affected in preview mode. wrangler dev would hang and give an error as it would try to send a request to https.

Through my research I figured out that Next internally uses process.env.__NEXT_PRIVATE_ORIGIN in standalone mode. They set it during startServer on this line. To align with this behavior in preview mode this should be set to the origin during the initialization.

Affected lines in Next:

proto would always be https here, thus the fetch below would recieve the wrong protocol in its fetchUrl.

@sommeeeer sommeeeer changed the title fix(preview): Ensure the protocol correct in redirects from server actions fix(preview): Ensure the protocol is correct in redirects from server actions May 29, 2025
@sommeeeer sommeeeer changed the title fix(preview): Ensure the protocol is correct in redirects from server actions fix(preview): Ensure the protocol is correct in redirects from server actions during preview mode May 29, 2025
Copy link

changeset-bot bot commented May 29, 2025

🦋 Changeset detected

Latest commit: ad79fcb

The changes in this PR will be included in the next version bump.

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

Copy link
Contributor

@vicb vicb 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 fix!

Could we drop the condition url.hostname === "localhost" and always set process.env.__NEXT_PRIVATE_ORIGIN?

Copy link

pkg-pr-new bot commented Jun 2, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/cloudflare@689

commit: ad79fcb

@sommeeeer
Copy link
Contributor Author

Could we drop the condition url.hostname === "localhost" and always set process.env.__NEXT_PRIVATE_ORIGIN?

In theory that shouldn't be a problem. fetchUrl computed by Next would be correct if the protocol is https. This fix is only necessary when the protocol is http. Its up to you.

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Thanks for both the fix and the detailed PR description.

I have updated the code to unconditionally apply the fix.

@vicb vicb merged commit 64a10a6 into opennextjs:main Jun 2, 2025
7 checks passed
@sommeeeer sommeeeer deleted the fix-preview-redirect branch June 2, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] NextAuth signOut request takes 15 seconds in preview mode
2 participants