fix: stabilize local dev auth startup#3252
Conversation
Gate Clerk-dependent renderer and desktop bridge setup when local config is absent, register the desktop schemes independently, proxy custom-scheme requests through the app protocol, and load the diff worker via the portable package worker entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Route configured loopback HTTP requests through the Vite origin so browser-session cookies are scoped to the page origin, while preserving direct WebSocket targets. Dedupe same-token pairing submits and tolerate stale one-time-token retries when a session is already authenticated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cd0056b. Configure here.
ApprovabilityVerdict: Needs human review This PR modifies authentication flow logic including credential submission, session validation, and desktop auth bridge enablement. Two unresolved medium-severity review comments identify potential bugs in proxy response buffering and session establishment timing. Changes to authentication code paths warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Stream desktop protocol proxy responses instead of buffering complete bodies, and wait for browser sessions to become observable after manual pairing exchanges. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

What Changed
Why
Local development could fail when Clerk config was missing or when running the web dev flow through
vp run dev. Clerk was being loaded too eagerly, desktop scheme registration depended on Clerk bridge setup, diff worker imports could fail under Vite, and pairing-token exchange could consume a one-time token before the browser session was observable on the correct origin.This keeps local startup resilient without Clerk config, avoids CORS/cookie-origin issues by using the web/Vite origin for browser HTTP requests, and preserves direct loopback WebSockets where required.
UI Changes
Checklist
Note
Medium Risk
Touches auth bootstrap, desktop protocol proxying, and environment URL resolution—important for cookies and pairing—but changes are scoped with broad test coverage.
Overview
Stabilizes local dev and desktop auth by decoupling startup from Clerk, fixing how API URLs are resolved, and hardening pairing-token exchange.
Desktop: When Clerk is not configured, the custom app scheme is registered at startup via
registerDesktopSchemePrivileges, and the Clerk SDK bridge is skipped throughmakeDesktopClerkLayer/desktopClerkBridgeEnabled. Custom-scheme proxying moves fromElectron.net.fetchto EffectHttpClient(Undici), with streamed bodies, hop-by-hop header stripping, andcache: no-store.Web: Primary environment HTTP targets loopback through the Vite dev origin when
VITE_DEV_SERVER_URLapplies, and throught3code-dev://appwhen the renderer runs on the desktop custom scheme (WebSocket bases stay direct). Pairing submit dedupes concurrent same-token calls, waits for session establishment after exchange, and treats 401 as success if the session is already authenticated. Clerk UI, cloud auth root, connections settings, and diff workers load lazily (portable worker URL) so missing Clerk config does not breakvp run dev. Vite exposesVITE_DEV_SERVER_URLand sets HMRclientPort.Reviewed by Cursor Bugbot for commit 6593a5f. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix local dev auth startup by stabilizing protocol, URL resolution, and credential submission
ElectronProtocol.proxyRequestto useHttpClientinstead ofElectron.net.fetch, streaming response bodies and stripping hop-by-hop headers; addsregisterDesktopSchemePrivilegedto configure the custom scheme at startup when the Clerk bridge is disableddesktopClerkBridgeEnabledinDesktopClerkand gates Clerk SDK bridge acquisition on that flag viamakeDesktopClerkLayerresolveHttpRequestBaseUrlin target.ts to prefer the Vite dev server origin for loopback targets in local dev and the custom desktop scheme origin (t3code-dev://app) when running in the desktop dev appsubmitServerAuthCredentialand adds a grace path that accepts an already-authenticated session on 401 when a duplicate token is submittedConfiguredCloudAuthRoot, sidebar Clerk components, and connection settings to defer Clerk initializationMacroscope summarized 6593a5f.