@@ -16,7 +16,7 @@ import {
1616} from '@/components/emcn'
1717import { client , useSession } from '@/lib/auth/auth-client'
1818import type { OAuthReturnContext } from '@/lib/credentials/client-state'
19- import { writeOAuthReturnContext } from '@/lib/credentials/client-state'
19+ import { ADD_CONNECTOR_SEARCH_PARAM , writeOAuthReturnContext } from '@/lib/credentials/client-state'
2020import {
2121 getCanonicalScopesForProvider ,
2222 getProviderIdFromServiceId ,
@@ -59,8 +59,8 @@ type OAuthModalConnectProps = OAuthModalBaseProps & {
5959 workspaceId : string
6060 credentialCount : number
6161} & (
62- | { workflowId : string ; knowledgeBaseId ?: never }
63- | { workflowId ?: never ; knowledgeBaseId : string }
62+ | { workflowId : string ; knowledgeBaseId ?: never ; connectorType ?: never }
63+ | { workflowId ?: never ; knowledgeBaseId : string ; connectorType ?: string }
6464 )
6565
6666interface OAuthModalReauthorizeProps extends OAuthModalBaseProps {
@@ -81,6 +81,7 @@ export function OAuthModal(props: OAuthModalProps) {
8181 const workspaceId = isConnect ? props . workspaceId : ''
8282 const workflowId = isConnect ? props . workflowId : undefined
8383 const knowledgeBaseId = isConnect ? props . knowledgeBaseId : undefined
84+ const connectorType = isConnect ? props . connectorType : undefined
8485 const toolName = ! isConnect ? props . toolName : ''
8586 const requiredScopes = ! isConnect ? ( props . requiredScopes ?? EMPTY_SCOPES ) : EMPTY_SCOPES
8687 const newScopes = ! isConnect ? ( props . newScopes ?? EMPTY_SCOPES ) : EMPTY_SCOPES
@@ -172,7 +173,7 @@ export function OAuthModal(props: OAuthModalProps) {
172173 }
173174
174175 const returnContext : OAuthReturnContext = knowledgeBaseId
175- ? { ...baseContext , origin : 'kb-connectors' as const , knowledgeBaseId }
176+ ? { ...baseContext , origin : 'kb-connectors' as const , knowledgeBaseId, connectorType }
176177 : { ...baseContext , origin : 'workflow' as const , workflowId : workflowId ! }
177178
178179 writeOAuthReturnContext ( returnContext )
@@ -205,7 +206,11 @@ export function OAuthModal(props: OAuthModalProps) {
205206 return
206207 }
207208
208- await client . oauth2 . link ( { providerId, callbackURL : window . location . href } )
209+ const callbackURL = new URL ( window . location . href )
210+ if ( connectorType ) {
211+ callbackURL . searchParams . set ( ADD_CONNECTOR_SEARCH_PARAM , connectorType )
212+ }
213+ await client . oauth2 . link ( { providerId, callbackURL : callbackURL . toString ( ) } )
209214 handleClose ( )
210215 } catch ( err ) {
211216 logger . error ( 'Failed to initiate OAuth connection' , { error : err } )
0 commit comments