modify oauth

pull/22091/head
JzoNg 11 months ago
parent 5781f45840
commit 9745570490

@ -90,10 +90,10 @@ const MCPDetailContent: FC<Props> = ({
setFalse: hideDeleting,
}] = useBoolean(false)
const handleOAuthCallback = useCallback((state: string) => {
const handleOAuthCallback = useCallback(() => {
if (!isCurrentWorkspaceManager)
return
if (detail.id !== state)
if (!detail.id)
return
handleUpdateTools()
}, [detail.id, handleUpdateTools, isCurrentWorkspaceManager])

@ -20,13 +20,11 @@ import MCPList from './mcp'
import { useSelector as useAppContextSelector } from '@/context/app-context'
import { useAllToolProviders } from '@/service/use-tools'
import { useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useOAuthCallback } from '@/hooks/use-oauth'
const ProviderList = () => {
const { t } = useTranslation()
const containerRef = useRef<HTMLDivElement>(null)
const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures)
useOAuthCallback()
const searchParams = useSearchParams()
const authCode = searchParams.get('code') || ''

@ -0,0 +1,10 @@
'use client'
import { useOAuthCallback } from '@/hooks/use-oauth'
const OAuthCallback = () => {
useOAuthCallback()
return <div />
}
export default OAuthCallback

@ -1,26 +1,18 @@
'use client'
import { useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
export const useOAuthCallback = () => {
const searchParams = useSearchParams()
useEffect(() => {
const MCPProviderID = searchParams.get('mcp_provider_id')
if (MCPProviderID && window.opener) {
if (window.opener) {
window.opener.postMessage({
type: 'oauth_callback',
payload: {
state: MCPProviderID,
},
}, '*')
window.close()
}
}, [searchParams])
}, [])
}
export const openOAuthPopup = (url: string, callback: (state: string) => void) => {
export const openOAuthPopup = (url: string, callback: () => void) => {
const width = 600
const height = 600
const left = window.screenX + (window.outerWidth - width) / 2
@ -35,8 +27,7 @@ export const openOAuthPopup = (url: string, callback: (state: string) => void) =
const handleMessage = (event: MessageEvent) => {
if (event.data?.type === 'oauth_callback') {
window.removeEventListener('message', handleMessage)
const { state } = event.data.payload
callback(state)
callback()
}
}

Loading…
Cancel
Save