Skip to content

Commit 4a67d0c

Browse files
committed
refactor debug to avoid toasting
1 parent 8e8eb41 commit 4a67d0c

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

client/src/App.tsx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,27 @@ const App = () => {
266266
[connectMcpServer],
267267
);
268268

269-
// Auto-connect to previously saved serverURL after OAuth callback
269+
// Update OAuth debug state during debug callback
270270
const onOAuthDebugConnect = useCallback(
271-
(_serverUrl: string, authorizationCode?: string) => {
271+
({
272+
authorizationCode,
273+
errorMsg,
274+
}: {
275+
authorizationCode?: string;
276+
errorMsg?: string;
277+
}) => {
272278
setIsAuthDebuggerVisible(true);
273279
if (authorizationCode) {
274280
updateAuthState({
275281
authorizationCode,
276282
oauthStep: "token_request",
277283
});
278284
}
285+
if (errorMsg) {
286+
updateAuthState({
287+
latestError: new Error(errorMsg),
288+
});
289+
}
279290
},
280291
[],
281292
);
@@ -553,28 +564,26 @@ const App = () => {
553564
);
554565

555566
// Helper function to render OAuth callback components
556-
const renderOAuthCallback = (
557-
path: string,
558-
onConnect: (serverUrl: string, authorizationCode?: string) => void,
559-
) => {
560-
const Component =
561-
path === "/oauth/callback"
562-
? React.lazy(() => import("./components/OAuthCallback"))
563-
: React.lazy(() => import("./components/OAuthDebugCallback"));
564-
567+
if (window.location.pathname === "/oauth/callback") {
568+
const OAuthCallback = React.lazy(
569+
() => import("./components/OAuthCallback"),
570+
);
565571
return (
566572
<Suspense fallback={<div>Loading...</div>}>
567-
<Component onConnect={onConnect} />
573+
<OAuthCallback onConnect={onOAuthConnect} />
568574
</Suspense>
569575
);
570-
};
571-
572-
if (window.location.pathname === "/oauth/callback") {
573-
return renderOAuthCallback(window.location.pathname, onOAuthConnect);
574576
}
575577

576578
if (window.location.pathname === "/oauth/callback/debug") {
577-
return renderOAuthCallback(window.location.pathname, onOAuthDebugConnect);
579+
const OAuthDebugCallback = React.lazy(
580+
() => import("./components/OAuthDebugCallback"),
581+
);
582+
return (
583+
<Suspense fallback={<div>Loading...</div>}>
584+
<OAuthDebugCallback onConnect={onOAuthDebugConnect} />
585+
</Suspense>
586+
);
578587
}
579588

580589
return (

client/src/components/OAuthDebugCallback.tsx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { useEffect } from "react";
22
import { SESSION_KEYS } from "../lib/constants";
3-
import { useToast } from "@/hooks/use-toast.ts";
43
import {
54
generateOAuthErrorDescription,
65
parseOAuthCallbackParams,
76
} from "@/utils/oauthUtils.ts";
87

98
interface OAuthCallbackProps {
10-
onConnect: (serverUrl: string, authorizationCode?: string) => void;
9+
onConnect: ({
10+
authorizationCode,
11+
errorMsg,
12+
}: {
13+
authorizationCode?: string;
14+
errorMsg?: string;
15+
}) => void;
1116
}
1217

1318
const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
14-
const { toast } = useToast();
15-
1619
useEffect(() => {
1720
let isProcessed = false;
1821

@@ -23,16 +26,11 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
2326
}
2427
isProcessed = true;
2528

26-
const notifyError = (description: string) =>
27-
void toast({
28-
title: "OAuth Authorization Error",
29-
description,
30-
variant: "destructive",
31-
});
32-
3329
const params = parseOAuthCallbackParams(window.location.search);
3430
if (!params.successful) {
35-
return notifyError(generateOAuthErrorDescription(params));
31+
const errorMsg = generateOAuthErrorDescription(params);
32+
onConnect({ errorMsg });
33+
return;
3634
}
3735

3836
const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
@@ -47,20 +45,13 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
4745
}
4846

4947
if (!params.code) {
50-
return notifyError("Missing authorization code");
48+
onConnect({ errorMsg: "Missing authorization code" });
49+
return;
5150
}
5251

5352
// Instead of storing in sessionStorage, pass the code directly
5453
// to the auth state manager through onConnect
55-
onConnect(serverUrl, params.code);
56-
57-
// Show success message
58-
toast({
59-
title: "Success",
60-
description:
61-
"Authorization code received. Returning to the Auth Debugger.",
62-
variant: "default",
63-
});
54+
onConnect({ authorizationCode: params.code });
6455
};
6556

6657
handleCallback().finally(() => {
@@ -74,7 +65,7 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
7465
return () => {
7566
isProcessed = true;
7667
};
77-
}, [toast, onConnect]);
68+
}, [onConnect]);
7869

7970
const callbackParams = parseOAuthCallbackParams(window.location.search);
8071

0 commit comments

Comments
 (0)