Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/web/src/components/clerk/authRedirect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from "vite-plus/test";

import { resolveClerkSignInProps } from "./authRedirect";

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

it("omits the redirect override on packaged desktop", () => {
expect(resolveClerkSignInProps("t3code://app/#/settings/general", true)).toEqual({});
});

it("omits the redirect override on development desktop", () => {
expect(resolveClerkSignInProps("t3code-dev://app/#/settings/general", true)).toEqual({});
});
});
12 changes: 12 additions & 0 deletions apps/web/src/components/clerk/authRedirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface ClerkSignInProps {
forceRedirectUrl?: string;
}

// Clerk's native-app allowlist only authorizes the bare renderer root
// (t3code://app/), which @clerk/electron's OAuth transport already supplies,
// so any page-derived redirect override gets the whole sign-in request
// rejected. On Electron, omit the override and let Clerk use its defaults.
export function resolveClerkSignInProps(href: string, isElectron: boolean): ClerkSignInProps {
if (isElectron) return {};
return { forceRedirectUrl: href };
}
5 changes: 4 additions & 1 deletion apps/web/src/components/clerk/useT3ConnectAuthPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useClerk } from "@clerk/react";

import { isElectron } from "../../env";
import { resolveClerkSignInProps } from "./authRedirect";

export function useT3ConnectAuthPrompt() {
const clerk = useClerk();
const openAuthPrompt = () => {
clerk.openSignIn({ forceRedirectUrl: window.location.href });
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron));
};
return { authPrompt: null, openAuthPrompt };
}
8 changes: 6 additions & 2 deletions apps/web/src/components/cloud/ConnectCliAuthSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
readConnectCliCallbackResult,
rememberConnectCliAuthState,
} from "../../cloud/connectCliAuth";
import { isElectron } from "../../env";
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
import { AuthSurfaceShell } from "../auth/AuthSurfaceShell";
import { resolveClerkSignInProps } from "../clerk/authRedirect";
import { Button } from "../ui/button";

function ConnectCliAuthMessage({
Expand Down Expand Up @@ -59,7 +61,7 @@ export function ConnectCliAuthorizeSurface() {
if (!isSignedIn) {
if (!signInOpened.current) {
signInOpened.current = true;
clerk.openSignIn({ forceRedirectUrl: window.location.href });
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron));
}
return;
}
Expand Down Expand Up @@ -95,7 +97,9 @@ export function ConnectCliAuthorizeSurface() {
<div className="mt-6">
<Button
type="button"
onClick={() => clerk.openSignIn({ forceRedirectUrl: window.location.href })}
onClick={() =>
clerk.openSignIn(resolveClerkSignInProps(window.location.href, isElectron))
}
>
Sign in
</Button>
Expand Down
Loading