Skip to content

Commit 5158c22

Browse files
committed
hoist state up to App
1 parent 2f8ab16 commit 5158c22

File tree

3 files changed

+212
-189
lines changed

3 files changed

+212
-189
lines changed

client/src/App.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
Tool,
1818
LoggingLevel,
1919
} from "@modelcontextprotocol/sdk/types.js";
20+
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
21+
import { SESSION_KEYS, getServerSpecificKey } from "./lib/constants";
22+
import { AuthDebuggerState } from "./lib/auth-types";
2023
import React, {
2124
Suspense,
2225
useCallback,
@@ -139,6 +142,26 @@ const App = () => {
139142
>
140143
>([]);
141144
const [isAuthDebuggerVisible, setIsAuthDebuggerVisible] = useState(false);
145+
146+
// Auth debugger state (moved from AuthDebugger component)
147+
const [authState, setAuthState] = useState<AuthDebuggerState>({
148+
isInitiatingAuth: false,
149+
oauthTokens: null,
150+
loading: true,
151+
oauthStep: "not_started",
152+
oauthMetadata: null,
153+
oauthClientInfo: null,
154+
authorizationUrl: null,
155+
authorizationCode: "",
156+
latestError: null,
157+
statusMessage: null,
158+
validationError: null,
159+
});
160+
161+
// Helper function to update specific auth state properties
162+
const updateAuthState = (updates: Partial<AuthDebuggerState>) => {
163+
setAuthState((prev) => ({ ...prev, ...updates }));
164+
};
142165
const nextRequestId = useRef(0);
143166
const rootsRef = useRef<Root[]>([]);
144167

@@ -246,6 +269,47 @@ const App = () => {
246269
setIsAuthDebuggerVisible(true);
247270
}, []);
248271

272+
// Load OAuth tokens when sseUrl changes (moved from AuthDebugger)
273+
useEffect(() => {
274+
const loadOAuthTokens = async () => {
275+
try {
276+
if (sseUrl) {
277+
const key = getServerSpecificKey(SESSION_KEYS.TOKENS, sseUrl);
278+
const tokens = sessionStorage.getItem(key);
279+
if (tokens) {
280+
const parsedTokens = await OAuthTokensSchema.parseAsync(
281+
JSON.parse(tokens),
282+
);
283+
updateAuthState({
284+
oauthTokens: parsedTokens,
285+
oauthStep: "complete",
286+
});
287+
}
288+
}
289+
} catch (error) {
290+
console.error("Error loading OAuth tokens:", error);
291+
} finally {
292+
updateAuthState({ loading: false });
293+
}
294+
};
295+
296+
loadOAuthTokens();
297+
}, [sseUrl]);
298+
299+
// Check for debug callback code (moved from AuthDebugger)
300+
useEffect(() => {
301+
const debugCode = sessionStorage.getItem(SESSION_KEYS.DEBUG_CODE);
302+
if (debugCode && sseUrl) {
303+
updateAuthState({
304+
authorizationCode: debugCode,
305+
oauthStep: "token_request",
306+
});
307+
308+
// Now that we've processed it, clear the debug code
309+
sessionStorage.removeItem(SESSION_KEYS.DEBUG_CODE);
310+
}
311+
}, [sseUrl]);
312+
249313
useEffect(() => {
250314
fetch(`${getMCPProxyAddress(config)}/config`)
251315
.then((response) => response.json())
@@ -485,6 +549,8 @@ const App = () => {
485549
<AuthDebugger
486550
sseUrl={sseUrl}
487551
onBack={() => setIsAuthDebuggerVisible(false)}
552+
authState={authState}
553+
updateAuthState={updateAuthState}
488554
/>
489555
</Suspense>
490556
);

0 commit comments

Comments
 (0)