fix: stabilize local dev auth startup #3252
Closedhuxcrux(GitHub profile, opens in a new tab)wants to merge 12 commits into
main fromrefs/pull/3252/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/electron/ElectronProtocol.ts line 167OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -109,6 +149,19 @@109149 if (request.method !== "GET" && request.method !== "HEAD") {110150 init.body = request.body;111151 (init as RequestInit & { duplex: "half" }).duplex = "half";112152 }113- const response = await Electron.net.fetch(targetUrl.toString(), init);114- return withContentSecurityPolicy(response, contentSecurityPolicy);153+154+ const effect = Effect.gen(function* () {155+ const clientRequest = HttpClientRequest.fromWeb(new Request(targetUrl, init));156+ const clientResponse = yield* httpClient.execute(clientRequest);157+ const body = request.method === "HEAD" ? null : yield* clientResponse.arrayBuffer;158+ return withContentSecurityPolicy(159+ new Response(body, {160+ status: clientResponse.status,161+ headers: clientResponse.headers,162+ }),163+ contentSecurityPolicy,164+ );165+ });166+167+ return Effect.runPromise(effect);apps/web/src/environments/primary/auth.ts line 330OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -287,2 +311,20 @@311+ bootstrapPromise = null;312+ stripPairingTokenFromUrl();313+ return;314+ }287315 resolvedAuthenticatedGateState = null;288- await exchangeBootstrapCredential(trimmedCredential);316+ try {317+ await exchangeBootstrapCredential(trimmedCredential);318+ } catch (error) {319+ if (isBootstrapHttpError(error) && error.status === 401) {320+ const currentSession = await fetchSessionState().catch(() => null);321+ if (currentSession?.authenticated) {322+ resolvedAuthenticatedGateState = { status: "authenticated" };323+ bootstrapPromise = null;324+ stripPairingTokenFromUrl();325+ return;326+ }327+ }328+ throw error;329+ }330+ resolvedAuthenticatedGateState = { status: "authenticated" };
juliusmarminge reviewed
@@ -121,6 +162,19 @@121162 if (request.method !== "GET" && request.method !== "HEAD") {122163 init.body = request.body;123164 (init as RequestInit & { duplex: "half" }).duplex = "half";124165 }125- const response = await Electron.net.fetch(targetUrl.toString(), init);126- return withContentSecurityPolicy(response, contentSecurityPolicy);166+167+ const effect = Effect.gen(function* () {168+ const clientRequest = HttpClientRequest.fromWeb(new Request(targetUrl, init));169+ const clientResponse = yield* httpClient.execute(clientRequest);170+ return withContentSecurityPolicy(171+ new Response(172+ request.method === "HEAD" ? null : Stream.toReadableStream(clientResponse.stream),173+ {174+ status: clientResponse.status,175+ headers: clientResponse.headers,176+ },177+ ),178+ contentSecurityPolicy,179+ );180+ });- @@ -4,9 +4,19 @@44 DesktopPreviewRecordingFrame,55 DesktopPreviewTabState,66 } from "@t3tools/contracts";7-import { exposeClerkBridge } from "@clerk/electron/preload";87 import { contextBridge, ipcRenderer } from "electron";98109 import * as IpcChannels from "./ipc/channels.ts";111012-exposeClerkBridge({ passkeys: true });11+declare const __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: string | undefined;12+13+const desktopClerkPreloadEnabled = Boolean(14+ typeof __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__ === "undefined"15+ ? undefined16+ : __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__.trim(),17+);18+19+if (desktopClerkPreloadEnabled) {20+ const { exposeClerkBridge } =21+ require("@clerk/electron/preload") as typeof import("@clerk/electron/preload");22+ exposeClerkBridge({ passkeys: true });
- @@ -272,5 +273,4 @@272273 useEffect(() => {273274 setAnchorMessageId(null);274275 lastScrolledAnchorMessageIdRef.current = null;275- freeze.set(false);276- }, [freeze, selectedThreadKey]);276+ }, [selectedThreadKey]);
huxcrux(GitHub profile, opens in a new tab) 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
Run ID:
4b99ca00-2b8d-42cd-a793-51b896f18c02You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share