From d2ac38445874788450fb81b404fe3882331dcdf0 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Mon, 23 Jun 2025 11:08:56 +0800 Subject: [PATCH] support re-authorization --- .../components/tools/mcp/detail/content.tsx | 18 +++++++----------- web/hooks/use-oauth.ts | 14 ++++++-------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/web/app/components/tools/mcp/detail/content.tsx b/web/app/components/tools/mcp/detail/content.tsx index 60f2c13b5f..366b4d8b85 100644 --- a/web/app/components/tools/mcp/detail/content.tsx +++ b/web/app/components/tools/mcp/detail/content.tsx @@ -25,7 +25,6 @@ import { useInvalidateMCPTools, useMCPTools, useUpdateMCP, - useUpdateMCPAuthorizationToken, useUpdateMCPTools, } from '@/service/use-tools' import { openOAuthPopup } from '@/hooks/use-oauth' @@ -53,7 +52,6 @@ const MCPDetailContent: FC = ({ const invalidateMCPTools = useInvalidateMCPTools() const { mutateAsync: updateTools, isPending: isUpdating } = useUpdateMCPTools() const { mutateAsync: authorizeMcp, isPending: isAuthorizing } = useAuthorizeMCP() - const { mutateAsync: updateMCPAuthorizationToken } = useUpdateMCPAuthorizationToken() const toolList = data?.tools || [] const handleUpdateTools = useCallback(async () => { @@ -62,7 +60,7 @@ const MCPDetailContent: FC = ({ await updateTools(detail.id) invalidateMCPTools(detail.id) onUpdate() - }, [detail, updateTools]) + }, [detail, invalidateMCPTools, onUpdate, updateTools]) const { mutate: updateMCP } = useUpdateMCP({ onSuccess: onUpdate, @@ -86,17 +84,13 @@ const MCPDetailContent: FC = ({ setFalse: hideDeleting, }] = useBoolean(false) - const handleOAuthCallback = async (state: string, code: string) => { + const handleOAuthCallback = useCallback((state: string) => { if (!isCurrentWorkspaceManager) return if (detail.id !== state) return - await updateMCPAuthorizationToken({ - provider_id: state, - authorization_code: code, - }) handleUpdateTools() - } + }, [detail.id, handleUpdateTools, isCurrentWorkspaceManager]) const handleAuthorize = useCallback(async () => { onFirstCreate() @@ -112,7 +106,7 @@ const MCPDetailContent: FC = ({ else if (res.authorization_url) openOAuthPopup(res.authorization_url, handleOAuthCallback) - }, [detail, updateMCP, hideUpdateModal, onUpdate]) + }, [onFirstCreate, isCurrentWorkspaceManager, detail, authorizeMcp, handleUpdateTools, handleOAuthCallback]) const handleUpdate = useCallback(async (data: any) => { if (!detail) @@ -137,11 +131,12 @@ const MCPDetailContent: FC = ({ hideDeleteConfirm() onUpdate(true) } - }, [detail, showDeleting, hideDeleting, hideDeleteConfirm, onUpdate]) + }, [detail, showDeleting, deleteMCP, hideDeleting, hideDeleteConfirm, onUpdate]) useEffect(() => { if (isCreation) handleAuthorize() + // eslint-disable-next-line react-hooks/exhaustive-deps }, []) if (!detail) @@ -175,6 +170,7 @@ const MCPDetailContent: FC = ({