MCPcopy Index your code
hub / github.com/simstudioai/sim / useOAuthReturnRouter

Function useOAuthReturnRouter

apps/sim/hooks/use-oauth-return.ts:60–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58 * - `kb-connectors`: Redirect to the KB page. The KB page picks up the context.
59 */
60export function useOAuthReturnRouter() {
61 const router = useRouter()
62 const params = useParams()
63 const workspaceId = params.workspaceId as string
64 const handledRef = useRef(false)
65
66 useEffect(() => {
67 if (handledRef.current) return
68 const ctx = readOAuthReturnContext()
69 if (!ctx) return
70 if (Date.now() - ctx.requestedAt > CONTEXT_MAX_AGE_MS) {
71 consumeOAuthReturnContext()
72 return
73 }
74
75 handledRef.current = true
76
77 if (ctx.origin === 'integrations') {
78 consumeOAuthReturnContext()
79 void (async () => {
80 const message = await resolveOAuthMessage(ctx)
81 toast.success(message)
82 dispatchCredentialUpdate(ctx)
83 })()
84 return
85 }
86
87 if (ctx.origin === 'workflow') {
88 try {
89 sessionStorage.removeItem(SETTINGS_RETURN_URL_KEY)
90 } catch {}
91 router.replace(`/workspace/${workspaceId}/w/${ctx.workflowId}`)
92 return
93 }
94
95 if (ctx.origin === 'kb-connectors') {
96 try {
97 sessionStorage.removeItem(SETTINGS_RETURN_URL_KEY)
98 } catch {}
99 const kbUrl = `/workspace/${workspaceId}/knowledge/${ctx.knowledgeBaseId}`
100 const connectorParam = ctx.connectorType
101 ? `?${ADD_CONNECTOR_SEARCH_PARAM}=${encodeURIComponent(ctx.connectorType)}`
102 : ''
103 router.replace(`${kbUrl}${connectorParam}`)
104 return
105 }
106 }, [router, workspaceId])
107}
108
109/**
110 * Post-OAuth handler for workflow pages.

Callers 3

HomeFunction · 0.90
IntegrationBlockDetailFunction · 0.90

Calls 6

readOAuthReturnContextFunction · 0.90
resolveOAuthMessageFunction · 0.85
dispatchCredentialUpdateFunction · 0.85
removeItemMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected