modify oauth

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

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

@ -20,13 +20,11 @@ import MCPList from './mcp'
import { useSelector as useAppContextSelector } from '@/context/app-context' import { useSelector as useAppContextSelector } from '@/context/app-context'
import { useAllToolProviders } from '@/service/use-tools' import { useAllToolProviders } from '@/service/use-tools'
import { useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useOAuthCallback } from '@/hooks/use-oauth'
const ProviderList = () => { const ProviderList = () => {
const { t } = useTranslation() const { t } = useTranslation()
const containerRef = useRef<HTMLDivElement>(null) const containerRef = useRef<HTMLDivElement>(null)
const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures)
useOAuthCallback()
const searchParams = useSearchParams() const searchParams = useSearchParams()
const authCode = searchParams.get('code') || '' 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' 'use client'
import { useEffect } from 'react' import { useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
export const useOAuthCallback = () => { export const useOAuthCallback = () => {
const searchParams = useSearchParams()
useEffect(() => { useEffect(() => {
const MCPProviderID = searchParams.get('mcp_provider_id') if (window.opener) {
if (MCPProviderID && window.opener) {
window.opener.postMessage({ window.opener.postMessage({
type: 'oauth_callback', type: 'oauth_callback',
payload: {
state: MCPProviderID,
},
}, '*') }, '*')
window.close() window.close()
} }
}, [searchParams]) }, [])
} }
export const openOAuthPopup = (url: string, callback: (state: string) => void) => { export const openOAuthPopup = (url: string, callback: () => void) => {
const width = 600 const width = 600
const height = 600 const height = 600
const left = window.screenX + (window.outerWidth - width) / 2 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) => { const handleMessage = (event: MessageEvent) => {
if (event.data?.type === 'oauth_callback') { if (event.data?.type === 'oauth_callback') {
window.removeEventListener('message', handleMessage) window.removeEventListener('message', handleMessage)
const { state } = event.data.payload callback()
callback(state)
} }
} }

Loading…
Cancel
Save