fix(web): unstick /connect after in-modal sign-in by redirecting to the authorize endpoint #5133
main fromrefs/pull/5133/head·merged by juliusmarminge View on GitHubFixes #5130
What happens#
In the t3 connect headless flow, app.t3.codes/connect opens the Clerk sign-in modal with forceRedirectUrl: window.location.href. On /connect that URL carries the #state=…&challenge=… fragment — and a same-URL navigation with a fragment is a same-document navigation the browser never performs as a reload. In the pinned @clerk/clerk-js@6.25.12, windowNavigate dispatches clerk:beforeunload unconditionally and setActive returns at its unload-tracker check before updating the session accessors (confirmed in the shipped bundle). Result: the modal closes, isSignedIn never flips, and the page sits on "Step 1 of 2" until a manual refresh. /connect is the only web route carrying a fragment, which is why only this flow is affected.
The fix (apps/web)#
Point the post-sign-in redirect straight at the Clerk authorize endpoint — a real cross-origin navigation, and exactly where the page's own effect would have sent an already-signed-in user (also saves a round trip). The callback page's sessionStorage state check is armed before hand-off, and signUpForceRedirectUrl covers the modal's sign-up branch against the same trap.
Validation#
pnpm testinapps/web: 196 files / 1747 tests pass, including 2 new tests for the redirect URL builder;pnpm typecheck, rootpnpm lint,vp fmt --checkclean.- The authorize origin passes Clerk's
allowedRedirectOriginsallowlist;signUpForceRedirectUrlverified present in the pinned@clerk/sharedtypes. - Caveat: the live passkey flow was not re-run in a browser against a patched build (the affected page is the hosted app), so a manual pass before merge is recommended. Repro recording of the broken flow: see #5130 (screenshots); happy to add a video of the "before" behavior if useful.
🤖 Generated with Claude Code
https://claude.ai/code/session_018SnL8Kiba6YBbxNnunPiHg
Note
Medium Risk Touches hosted CLI OAuth and Clerk redirect behavior; misconfiguration could break connect sign-in, but changes are scoped with tests and sessionStorage state is armed before hand-off.
Overview
Fixes the t3 connect hosted flow where signing in from the Clerk modal on /connect left isSignedIn stuck and the UI on “Step 1 of 2” until a refresh.
Post–sign-in redirect no longer targets window.location.href on /connect (same URL + fragment → no real navigation, so Clerk never updates session state). It now uses a new connectCliSignInRedirectUrl helper that points at Clerk’s /oauth/authorize URL (same destination an already-signed-in user would get), with fallback to the current URL if CLI OAuth isn’t configured.
ConnectCliAuthorizeSurface centralizes openSignIn, arms rememberConnectCliAuthState before opening the modal, and passes the authorize URL into resolveClerkSignInProps. Web sign-in props now set signUpForceRedirectUrl alongside forceRedirectUrl so the sign-up path in the modal doesn’t hit the same trap.
Note
Fix /connect page getting stuck after in-modal sign-in by redirecting to the authorize endpoint#
- When a user signs in via the Clerk modal on
/connect, the post-sign-in redirect now points to the/oauth/authorizeendpoint (built viabuildConnectCliClerkAuthorizeUrl) instead of the current/connectURL, which previously left the page stuck. - A new
connectCliSignInRedirectUrlhelper inconnectCliAuth.tsconstructs this redirect URL, falling back to the currenthrefif the authorize URL cannot be built. ConnectCliAuthorizeSurfacenow callsrememberConnectCliAuthStateto persist request state before opening the Clerk sign-in modal.resolveClerkSignInPropsnow includessignUpForceRedirectUrlmatchingforceRedirectUrlon web, so switching from sign-in to sign-up inside the modal also redirects correctly.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved 7a839fb
This is a straightforward bug fix that changes the post-sign-in redirect URL to work around browser fragment navigation behavior. The changes are self-contained, well-documented, and include unit tests.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisa7c5ad5
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
86138717-00f9-4b13-90ae-5eb1b49e866fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share