Skip to content

Commit e2dd22b

Browse files
fix(desktop): omit Clerk redirect override on Electron instead of normalizing it
The pre-GA flow signed in with Clerk's default redirects and worked; the GA change broke desktop by forcing window.location.href, whose page-derived URL fails Clerk's native redirect allowlist. Rather than passing a normalized root URL, drop the override entirely on Electron so the sign-in request is identical to the previously working configuration — @clerk/electron's OAuth transport already supplies the allowlisted t3code://app/ callback. Browser flows keep returning to the exact page that started auth. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 99d735e commit e2dd22b

4 files changed

Lines changed: 24 additions & 26 deletions

File tree

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { resolveClerkAuthRedirectUrl } from "./authRedirect";
3+
import { resolveClerkSignInProps } from "./authRedirect";
44

5-
describe("resolveClerkAuthRedirectUrl", () => {
6-
it("preserves the current browser URL", () => {
5+
describe("resolveClerkSignInProps", () => {
6+
it("returns to the current browser URL on the web", () => {
77
const href = "https://app.t3.codes/connect?state=state-1#details";
8-
expect(resolveClerkAuthRedirectUrl(href, false)).toBe(href);
8+
expect(resolveClerkSignInProps(href, false)).toEqual({ forceRedirectUrl: href });
99
});
1010

11-
it("uses the allowlisted packaged desktop callback", () => {
12-
expect(resolveClerkAuthRedirectUrl("t3code://app/continue#/settings/general", true)).toBe(
13-
"t3code://app/",
14-
);
11+
it("omits the redirect override on packaged desktop", () => {
12+
expect(resolveClerkSignInProps("t3code://app/#/settings/general", true)).toEqual({});
1513
});
1614

17-
it("uses the allowlisted development desktop callback", () => {
18-
expect(resolveClerkAuthRedirectUrl("t3code-dev://app/continue#/settings/general", true)).toBe(
19-
"t3code-dev://app/",
20-
);
15+
it("omits the redirect override on development desktop", () => {
16+
expect(resolveClerkSignInProps("t3code-dev://app/#/settings/general", true)).toEqual({});
2117
});
2218
});
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export function resolveClerkAuthRedirectUrl(href: string, isElectron: boolean): string {
2-
if (!isElectron) return href;
3-
return new URL("/", href).toString();
1+
export interface ClerkSignInProps {
2+
forceRedirectUrl?: string;
3+
}
4+
5+
// Clerk's native-app allowlist only authorizes the bare renderer root
6+
// (t3code://app/), which @clerk/electron's OAuth transport already supplies,
7+
// so any page-derived redirect override gets the whole sign-in request
8+
// rejected. On Electron, omit the override and let Clerk use its defaults.
9+
export function resolveClerkSignInProps(href: string, isElectron: boolean): ClerkSignInProps {
10+
if (isElectron) return {};
11+
return { forceRedirectUrl: href };
412
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { useClerk } from "@clerk/react";
22

33
import { isElectron } from "../../env";
4-
import { resolveClerkAuthRedirectUrl } from "./authRedirect";
4+
import { resolveClerkSignInProps } from "./authRedirect";
55

66
export function useT3ConnectAuthPrompt() {
77
const clerk = useClerk();
88
const openAuthPrompt = () => {
9-
clerk.openSignIn({
10-
forceRedirectUrl: resolveClerkAuthRedirectUrl(window.location.href, isElectron),
11-
});
9+
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron));
1210
};
1311
return { authPrompt: null, openAuthPrompt };
1412
}

‎apps/web/src/components/cloud/ConnectCliAuthSurface.tsx‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { isElectron } from "../../env";
1212
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
1313
import { AuthSurfaceShell } from "../auth/AuthSurfaceShell";
14-
import { resolveClerkAuthRedirectUrl } from "../clerk/authRedirect";
14+
import { resolveClerkSignInProps } from "../clerk/authRedirect";
1515
import { Button } from "../ui/button";
1616

1717
function ConnectCliAuthMessage({
@@ -61,9 +61,7 @@ export function ConnectCliAuthorizeSurface() {
6161
if (!isSignedIn) {
6262
if (!signInOpened.current) {
6363
signInOpened.current = true;
64-
clerk.openSignIn({
65-
forceRedirectUrl: resolveClerkAuthRedirectUrl(window.location.href, isElectron),
66-
});
64+
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron));
6765
}
6866
return;
6967
}
@@ -100,9 +98,7 @@ export function ConnectCliAuthorizeSurface() {
10098
<Button
10199
type="button"
102100
onClick={() =>
103-
clerk.openSignIn({
104-
forceRedirectUrl: resolveClerkAuthRedirectUrl(window.location.href, isElectron),
105-
})
101+
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron))
106102
}
107103
>
108104
Sign in

0 commit comments

Comments
 (0)