@@ -46,6 +46,7 @@ import { useSession } from '@/lib/auth/auth-client'
4646import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/base-tool'
4747import { consumeOAuthReturnContext , writeOAuthReturnContext } from '@/lib/credentials/client-state'
4848import type { OAuthProvider } from '@/lib/oauth'
49+ import { usesCredentialConfiguredOAuthClient } from '@/lib/oauth/utils'
4950import { OPERATION_SUBBLOCK_ID } from '@/lib/permission-groups/operation-access'
5051import {
5152 DEFAULT_HORIZONTAL_SPACING ,
@@ -343,6 +344,9 @@ const WorkflowContent = React.memo(
343344 requiredScopes : string [ ]
344345 newScopes ?: string [ ]
345346 } | null > ( null )
347+ const oauthModalRequiresDraft = oauthModal
348+ ? usesCredentialConfiguredOAuthClient ( oauthModal . provider )
349+ : false
346350
347351 const params = useParams ( )
348352 const router = useRouter ( )
@@ -589,16 +593,18 @@ const WorkflowContent = React.memo(
589593 const detail = ( event as CustomEvent < OAuthConnectEventDetail > ) . detail
590594 if ( ! detail ) return
591595
592- writeOAuthReturnContext ( {
593- origin : 'workflow' ,
594- workflowId : workflowIdParam ,
595- displayName : detail . providerName ,
596- providerId : detail . providerId ,
597- preCount : 0 ,
598- workspaceId,
599- reconnect : true ,
600- requestedAt : Date . now ( ) ,
601- } )
596+ if ( ! usesCredentialConfiguredOAuthClient ( detail . providerId ) ) {
597+ writeOAuthReturnContext ( {
598+ origin : 'workflow' ,
599+ workflowId : workflowIdParam ,
600+ displayName : detail . providerName ,
601+ providerId : detail . providerId ,
602+ preCount : 0 ,
603+ workspaceId,
604+ reconnect : true ,
605+ requestedAt : Date . now ( ) ,
606+ } )
607+ }
602608
603609 setOauthModal ( {
604610 provider : detail . providerId as OAuthProvider ,
@@ -5342,7 +5348,27 @@ const WorkflowContent = React.memo(
53425348
53435349 { ! embedded && < Panel /> }
53445350
5345- { ! embedded && oauthModal && (
5351+ { ! embedded && oauthModal && oauthModalRequiresDraft && (
5352+ < ConnectOAuthModal
5353+ mode = 'connect'
5354+ origin = 'workflow'
5355+ open = { true }
5356+ onOpenChange = { ( open ) => {
5357+ if ( ! open ) {
5358+ consumeOAuthReturnContext ( )
5359+ setOauthModal ( null )
5360+ }
5361+ } }
5362+ provider = { oauthModal . provider }
5363+ providerId = { oauthModal . provider }
5364+ serviceId = { oauthModal . serviceId }
5365+ requiredScopes = { oauthModal . requiredScopes }
5366+ workspaceId = { workspaceId }
5367+ workflowId = { workflowIdParam }
5368+ />
5369+ ) }
5370+
5371+ { ! embedded && oauthModal && ! oauthModalRequiresDraft && (
53465372 < ConnectOAuthModal
53475373 mode = 'reauthorize'
53485374 open = { true }
0 commit comments