Skip to content

Commit 0362fde

Browse files
committed
Fix Connect approval toggle stuck on load failure, mint replay loss, and concurrent action race
- Revert decodeSecurityMode to fall back to 'account' for invalid persisted values instead of failing with ConnectSecurityModeLoadError. This prevents the UI toggle from being permanently disabled when the secret store contains corrupt data, and also prevents mint replay guard consumption from being wasted when getSecurityMode fails after guards are consumed. - Add synchronous useRef guard in handleConnectClientAction to prevent concurrent approve/reject/revoke calls that can slip through the asynchronous React state check before re-render disables buttons.
1 parent 136150d commit 0362fde

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

‎apps/server/src/auth/ConnectClientStore.ts‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,9 @@ function fromPresentationMetadata(
222222
};
223223
}
224224

225-
function decodeSecurityMode(
226-
bytes: Uint8Array,
227-
): Effect.Effect<AuthConnectSecurityMode, ConnectSecurityModeLoadError> {
225+
function decodeSecurityMode(bytes: Uint8Array): AuthConnectSecurityMode {
228226
const value = textDecoder.decode(bytes).trim();
229-
if (value === "account" || value === "client-approval") {
230-
return Effect.succeed(value);
231-
}
232-
return Effect.fail(
233-
new ConnectSecurityModeLoadError({
234-
cause: new Error(`Invalid Connect security mode: ${value}`),
235-
}),
236-
);
227+
return value === "account" || value === "client-approval" ? value : "account";
237228
}
238229

239230
function encodeSecurityMode(mode: AuthConnectSecurityMode): Uint8Array {
@@ -265,10 +256,10 @@ export const make = Effect.gen(function* () {
265256

266257
const getSecurityMode: ConnectClientStore["Service"]["getSecurityMode"] = () =>
267258
secrets.get(CONNECT_SECURITY_MODE_SECRET).pipe(
268-
Effect.mapError((cause) => new ConnectSecurityModeLoadError({ cause })),
269-
Effect.flatMap((mode) =>
270-
Option.isSome(mode) ? decodeSecurityMode(mode.value) : Effect.succeed("account" as const),
259+
Effect.map((mode) =>
260+
Option.isSome(mode) ? decodeSecurityMode(mode.value) : ("account" as const),
271261
),
262+
Effect.mapError((cause) => new ConnectSecurityModeLoadError({ cause })),
272263
Effect.withSpan("ConnectClientStore.getSecurityMode"),
273264
);
274265

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
TriangleAlertIcon,
99
} from "lucide-react";
1010
import { useAuth } from "@clerk/react";
11-
import { type ReactNode, memo, useCallback, useEffect, useMemo, useState } from "react";
11+
import { type ReactNode, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
1212
import {
1313
AuthAccessReadScope,
1414
AuthAccessWriteScope,
@@ -2224,6 +2224,7 @@ export function ConnectionsSettings() {
22242224
const [pendingConnectClientActionKey, setPendingConnectClientActionKey] = useState<string | null>(
22252225
null,
22262226
);
2227+
const pendingConnectClientActionRef = useRef(false);
22272228
const [addBackendDialogOpen, setAddBackendDialogOpen] = useState(false);
22282229
const [savedBackendMode, setSavedBackendMode] = useState<"remote" | "ssh">("remote");
22292230
const [savedBackendHost, setSavedBackendHost] = useState("");
@@ -2549,7 +2550,8 @@ export function ConnectionsSettings() {
25492550

25502551
const handleConnectClientAction = useCallback(
25512552
async (action: "approve" | "reject" | "revoke", clientProofKeyThumbprint: string) => {
2552-
if (pendingConnectClientActionKey !== null) return;
2553+
if (pendingConnectClientActionRef.current) return;
2554+
pendingConnectClientActionRef.current = true;
25532555
const actionKey = `${action}:${clientProofKeyThumbprint}`;
25542556
setPendingConnectClientActionKey(actionKey);
25552557
setDesktopAccessManagementMutationError(null);
@@ -2573,10 +2575,11 @@ export function ConnectionsSettings() {
25732575
}),
25742576
);
25752577
} finally {
2578+
pendingConnectClientActionRef.current = false;
25762579
setPendingConnectClientActionKey(null);
25772580
}
25782581
},
2579-
[pendingConnectClientActionKey],
2582+
[],
25802583
);
25812584

25822585
const handleAddSavedBackend = useCallback(async () => {

0 commit comments

Comments
 (0)