fix(ui): remove duplicate extractErrorMessage, sessionStorage-only in admin OAuth hook, call delete API on disconnect

This commit is contained in:
Ishaan Jaffer 2026-03-11 08:14:43 -07:00
parent 035c593999
commit ef3efcff21
2 changed files with 10 additions and 15 deletions

View file

@ -3,7 +3,7 @@
import React, { useCallback, useEffect, useState } from "react";
import { Spin, Input, Button, Skeleton } from "antd";
import { SearchOutlined, ArrowLeftOutlined, RightOutlined, ToolOutlined, CheckCircleOutlined } from "@ant-design/icons";
import { fetchMCPServers, getMCPOAuthUserCredentialStatus, listMCPTools } from "../networking";
import { deleteMCPOAuthUserCredential, fetchMCPServers, getMCPOAuthUserCredentialStatus, listMCPTools } from "../networking";
import { AUTH_TYPE, MCPServer, MCPTool, handleTransport } from "../mcp_tools/types";
import { message } from "antd";
import { useUserMcpOAuthFlow } from "@/hooks/useUserMcpOAuthFlow";
@ -276,7 +276,12 @@ const MCPAppsPanel: React.FC<Props> = ({ accessToken, selectedServers, onChange
<Button
type="default"
danger
onClick={() => {
onClick={async () => {
try {
await deleteMCPOAuthUserCredential(accessToken, detailServer.server_id);
} catch (_) {
// Ignore — credential may already be gone; update UI regardless.
}
setOauthConnected((prev) => { const n = new Set(prev); n.delete(detailServer.server_id); return n; });
}}
style={{ borderRadius: 8, fontWeight: 600, height: 38, minWidth: 110 }}

View file

@ -14,17 +14,6 @@ import { extractErrorMessage } from "@/utils/errorUtils";
export type McpOAuthStatus = "idle" | "authorizing" | "exchanging" | "success" | "error";
function extractErrorMessage(err: unknown): string {
if (err instanceof Error) return err.message;
if (err && typeof err === "object") {
const e = err as Record<string, unknown>;
if (typeof e.detail === "string") return e.detail;
if (typeof e.message === "string") return e.message;
return JSON.stringify(err);
}
return String(err);
}
interface UseMcpOAuthFlowOptions {
accessToken: string | null;
getCredentials: () => {
@ -91,9 +80,10 @@ export const useMcpOAuthFlow = ({
const setStorageItem = (key: string, value: string) => {
if (typeof window === "undefined") return;
try {
// Store in both sessionStorage and localStorage for redundancy
// Use sessionStorage only — the flow state may contain client credentials;
// writing them to localStorage would persist across browser sessions and
// make them readable by any injected script (XSS).
window.sessionStorage.setItem(key, value);
window.localStorage.setItem(key, value);
} catch (err) {
console.warn(`Failed to set storage item ${key}`, err);
}