Skip to content

Commit 7da7159

Browse files
jonathanlabclaude
andauthored
feat: allow users to cancel oauth (#155)
Co-authored-by: Claude <[email protected]>
1 parent 18eeb61 commit 7da7159

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

apps/array/src/main/preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ contextBridge.exposeInMainWorld("electronAPI", {
5757
region: CloudRegion,
5858
): Promise<{ success: boolean; data?: OAuthTokenResponse; error?: string }> =>
5959
ipcRenderer.invoke("oauth:refresh-token", refreshToken, region),
60+
oauthCancelFlow: (): Promise<{ success: boolean; error?: string }> =>
61+
ipcRenderer.invoke("oauth:cancel-flow"),
6062
selectDirectory: (): Promise<string | null> =>
6163
ipcRenderer.invoke("select-directory"),
6264
searchDirectories: (query: string, searchRoot?: string): Promise<string[]> =>

apps/array/src/main/services/oauth.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,19 @@ export function registerOAuthHandlers(): void {
396396
}
397397
},
398398
);
399+
400+
ipcMain.handle("oauth:cancel-flow", async () => {
401+
try {
402+
if (activeCloseServer) {
403+
activeCloseServer();
404+
activeCloseServer = null;
405+
}
406+
return { success: true };
407+
} catch (error) {
408+
return {
409+
success: false,
410+
error: error instanceof Error ? error.message : "Unknown error",
411+
};
412+
}
413+
});
399414
}

apps/array/src/renderer/features/auth/components/AuthScreen.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Flex,
1111
Heading,
1212
Select,
13+
Spinner,
1314
Text,
1415
} from "@radix-ui/themes";
1516
import type { CloudRegion } from "@shared/types/oauth";
@@ -84,9 +85,14 @@ export function AuthScreen() {
8485
},
8586
});
8687

87-
const handleSignIn = () => {
88-
setWorkspaceError(null);
89-
authMutation.mutate({ selectedRegion: region, workspace });
88+
const handleSignIn = async () => {
89+
if (authMutation.isPending) {
90+
authMutation.reset();
91+
await window.electronAPI.oauthCancelFlow();
92+
} else {
93+
setWorkspaceError(null);
94+
authMutation.mutate({ selectedRegion: region, workspace });
95+
}
9096
};
9197

9298
const handleRegionChange = (value: string) => {
@@ -175,14 +181,16 @@ export function AuthScreen() {
175181

176182
<Button
177183
onClick={handleSignIn}
178-
disabled={authMutation.isPending || !workspace}
179-
variant="classic"
184+
disabled={!workspace}
185+
variant={"classic"}
180186
size="3"
181187
mt="2"
182-
loading={authMutation.isPending}
188+
color={authMutation.isPending ? "gray" : undefined}
183189
>
190+
{authMutation.isPending && <Spinner />}
191+
184192
{authMutation.isPending
185-
? "Waiting for authorization..."
193+
? "Cancel authorization"
186194
: "Sign in with PostHog"}
187195
</Button>
188196
</Flex>

apps/array/src/renderer/features/settings/components/SettingsView.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Flex,
1515
Heading,
1616
Select,
17+
Spinner,
1718
Switch,
1819
Text,
1920
} from "@radix-ui/themes";
@@ -62,8 +63,11 @@ export function SettingsView() {
6263
},
6364
});
6465

65-
const handleReauthenticate = () => {
66-
if (cloudRegion) {
66+
const handleReauthenticate = async () => {
67+
if (reauthMutation.isPending) {
68+
reauthMutation.reset();
69+
await window.electronAPI.oauthCancelFlow();
70+
} else if (cloudRegion) {
6771
reauthMutation.mutate(cloudRegion);
6872
}
6973
};
@@ -263,11 +267,11 @@ export function SettingsView() {
263267
variant="classic"
264268
size="1"
265269
onClick={handleReauthenticate}
266-
disabled={reauthMutation.isPending}
267-
loading={reauthMutation.isPending}
270+
color={reauthMutation.isPending ? "gray" : undefined}
268271
>
272+
{reauthMutation.isPending && <Spinner />}
269273
{reauthMutation.isPending
270-
? "Authenticating..."
274+
? "Cancel authorization"
271275
: "Re-authenticate"}
272276
</Button>
273277
<Button

apps/array/src/renderer/types/electron.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ declare global {
3535
data?: OAuthTokenResponse;
3636
error?: string;
3737
}>;
38+
oauthCancelFlow: () => Promise<{ success: boolean; error?: string }>;
3839
selectDirectory: () => Promise<string | null>;
3940
searchDirectories: (
4041
query: string,

0 commit comments

Comments
 (0)