support re-authorization

This commit is contained in:
JzoNg
2025-06-23 11:08:56 +08:00
parent 2b0193dd79
commit d2ac384458
2 changed files with 13 additions and 19 deletions

View File

@ -6,15 +6,13 @@ export const useOAuthCallback = () => {
const searchParams = useSearchParams()
useEffect(() => {
const code = searchParams.get('code')
const state = searchParams.get('state')
const MCPProviderID = searchParams.get('mcp_provider_id')
if (code && state && window.opener) {
if (MCPProviderID && window.opener) {
window.opener.postMessage({
type: 'oauth_callback',
payload: {
code,
state,
state: MCPProviderID,
},
}, '*')
window.close()
@ -22,7 +20,7 @@ export const useOAuthCallback = () => {
}, [searchParams])
}
export const openOAuthPopup = (url: string, callback: (state: string, code: string) => void) => {
export const openOAuthPopup = (url: string, callback: (state: string) => void) => {
const width = 600
const height = 600
const left = window.screenX + (window.outerWidth - width) / 2
@ -37,8 +35,8 @@ export const openOAuthPopup = (url: string, callback: (state: string, code: stri
const handleMessage = (event: MessageEvent) => {
if (event.data?.type === 'oauth_callback') {
window.removeEventListener('message', handleMessage)
const { code, state } = event.data.payload
callback(state, code)
const { state } = event.data.payload
callback(state)
}
}