Let a preview sign in on its alias URL - #25
Merged
Conversation
✅ Deploy Preview for base44-platform-starter ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Netlify answers the deploy alias, deploy-preview-N--<site>.netlify.app, but hands the server handler the deploy permalink, <deploy-id>--<site>.netlify.app, in host and x-forwarded-host. Derived from the request, a preview named the permalink as the redirect proxy's forwarding target while the browser held the host-only state cookie on the alias, so every sign-in died as InvalidCheck: state value could not be parsed which is also what a missing cookie reports: parseCookie in @auth/core rewrites every cause into that one string. Netlify's own DEPLOY_PRIME_URL is the alias, so pin AUTH_URL to it. next.config.ts bakes the value into the build because the function's runtime environment does not carry Netlify's build variables. The pin applies only where no origin is set explicitly, leaving production, which sets NEXTAUTH_URL, and local dev, which sets neither, exactly as they were. Measured on the live deployments: /api/auth/providers on PR #24's alias reported the permalink as its own callback URL. Verified locally by building with DEPLOY_PRIME_URL=http://pinned-alias.example and requesting with a permalink Host: the decoded OAuth state carried the pinned origin, and redirect_uri stayed production's. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
NitzanSirota
force-pushed
the
fix/preview-auth-alias-origin
branch
from
September 2, 2026 11:15
b67630c to
e4d10ee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #23. The redirect proxy shipped there works — production forwards the callback correctly — but no preview could actually complete a sign-in.
The bug
Netlify answers the deploy alias (
deploy-preview-N--<site>.netlify.app) with a200, but hands the Next.js server handler the deploy permalink (<deploy-id>--<site>.netlify.app) inhost/x-forwarded-host. Measured on the live deployments —/api/auth/providerson PR #24's alias reported the permalink as its owncallbackUrl.So, with the origin derived from the request:
statecookie is set there — cookies are host-only;state;statecookie.Sign-in fails as
InvalidCheck: state value could not be parsed. That message is misleading:parseCookiein@auth/corewraps every cause — a missing cookie included — into that one string, which is why this first looked like a stale cookie or a database problem.The fix
Netlify's own
DEPLOY_PRIME_URLis the alias, so pinAUTH_URLto it.next.config.tsbakes it in at build time, because the function's runtime environment does not carry Netlify's build variables.src/lib/auth.tsapplies the pin only when neitherAUTH_URLnorNEXTAUTH_URLis already set, so production (which setsNEXTAUTH_URL) and local dev (which sets neither) are unchanged.AUTH_URLis the only channel available — v5 has nourlconfig option.Verification
Built with
DEPLOY_PRIME_URL=http://pinned-alias.example, served it, and sent a request withHost: 6a97fdd1--permalink.netlify.app:state→origin: http://pinned-alias.example/api/auth/callback/google— the pinned value, not the host;redirect_uri→ still production's callback, so the proxy is untouched.npm run typecheckclean,npm run lintat its two pre-existingexhaustive-depswarnings,npm run buildexit 0.What this PR's own preview proves:
curl -s <this preview's alias>/api/auth/providersshould report the alias ascallbackUrl. If it still reports the permalink,DEPLOY_PRIME_URLwas absent from the build environment and the bake came out empty — the one step that cannot be verified off-platform.Trade-off
A preview now signs in on its alias URL only. Opening the permalink directly puts the browser on a host the deployment no longer claims. Documented in
docs/deploy.md.No Netlify configuration changes required.
🤖 Generated with Claude Code