Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): unstick /connect after in-modal sign-in by redirecting to the authorize endpoint #5133

MergedTorbenWetter(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/5133/headmerged by juliusmarminge View on GitHub

Fixes #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 test in apps/web: 196 files / 1747 tests pass, including 2 new tests for the redirect URL builder; pnpm typecheck, root pnpm lint, vp fmt --check clean.
  • The authorize origin passes Clerk's allowedRedirectOrigins allowlist; signUpForceRedirectUrl verified present in the pinned @clerk/shared types.
  • 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.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7a839fbe561ac7c761d62f19d2ee2d6479bee3d4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

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/authorize endpoint (built via buildConnectCliClerkAuthorizeUrl) instead of the current /connect URL, which previously left the page stuck.
  • A new connectCliSignInRedirectUrl helper in connectCliAuth.ts constructs this redirect URL, falling back to the current href if the authorize URL cannot be built.
  • ConnectCliAuthorizeSurface now calls rememberConnectCliAuthState to persist request state before opening the Clerk sign-in modal.
  • resolveClerkSignInProps now includes signUpForceRedirectUrl matching forceRedirectUrl on web, so switching from sign-in to sign-up inside the modal also redirects correctly.
Macroscope summarized 7a839fb.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 86138717-00f9-4b13-90ae-5eb1b49e866f

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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).
    4. juliusmarminge merged thisa7c5ad5

    5. juliusmarminge closed this

Sign in to join this conversation.