Skip to content

Commit f3880ad

Browse files
fix(gmail-webhook): gmail webhook credential injection issue with webhook block (#865)
1 parent 936705f commit f3880ad

File tree

2 files changed

+21
-23
lines changed
  • apps/sim
    • app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/webhook
    • blocks/blocks

2 files changed

+21
-23
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/webhook/webhook.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '@/components/icons'
1515
import { Button } from '@/components/ui/button'
1616
import { createLogger } from '@/lib/logs/console/logger'
17-
import { ToolCredentialSelector } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/tool-input/components/tool-credential-selector'
1817
import { WebhookModal } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/webhook/components'
1918
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/hooks/use-sub-block-value'
2019
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
@@ -331,7 +330,6 @@ export function WebhookConfig({
331330
const params = useParams()
332331
const workflowId = params.workflowId as string
333332
const [isLoading, setIsLoading] = useState(false)
334-
const [gmailCredentialId, setGmailCredentialId] = useState<string>('')
335333

336334
// No need to manage webhook status separately - it's determined by having provider + path
337335

@@ -341,6 +339,9 @@ export function WebhookConfig({
341339
// Store the webhook path
342340
const [storeWebhookPath, setWebhookPath] = useSubBlockValue(blockId, 'webhookPath')
343341

342+
// Store Gmail credential from the dedicated subblock
343+
const [storeGmailCredential, setGmailCredential] = useSubBlockValue(blockId, 'gmailCredential')
344+
344345
// Don't auto-generate webhook paths - only create them when user actually configures a webhook
345346
// This prevents the "Active Webhook" badge from showing on unconfigured blocks
346347

@@ -351,6 +352,7 @@ export function WebhookConfig({
351352
const webhookProvider = propValue?.webhookProvider ?? storeWebhookProvider
352353
const webhookPath = propValue?.webhookPath ?? storeWebhookPath
353354
const providerConfig = propValue?.providerConfig ?? storeProviderConfig
355+
const gmailCredentialId = storeGmailCredential || ''
354356

355357
// Store the actual provider from the database
356358
const [actualProvider, setActualProvider] = useState<string | null>(null)
@@ -444,7 +446,7 @@ export function WebhookConfig({
444446

445447
// Clear component state
446448
setError(null)
447-
setGmailCredentialId('')
449+
setGmailCredential('')
448450

449451
// Note: Store will be cleared AFTER successful database deletion
450452
// This ensures store and database stay perfectly in sync
@@ -695,31 +697,12 @@ export function WebhookConfig({
695697
// Check if the webhook is connected for the selected provider
696698
const isWebhookConnected = webhookId && webhookProvider === actualProvider
697699

698-
const handleCredentialChange = (credentialId: string) => {
699-
if (isPreview || disabled) return
700-
setGmailCredentialId(credentialId)
701-
}
702-
703-
// For Gmail, we need to show the credential selector
700+
// For Gmail, show configure button when credential is available and webhook not connected
704701
if (webhookProvider === 'gmail' && !isWebhookConnected) {
705702
return (
706703
<div className='w-full'>
707704
{error && <div className='mb-2 text-red-500 text-sm dark:text-red-400'>{error}</div>}
708705

709-
<div className='mb-3'>
710-
<ToolCredentialSelector
711-
value={gmailCredentialId}
712-
onChange={handleCredentialChange}
713-
provider='google-email'
714-
requiredScopes={[
715-
'https://www.googleapis.com/auth/gmail.modify',
716-
'https://www.googleapis.com/auth/gmail.labels',
717-
]}
718-
label='Select Gmail account'
719-
disabled={isConnecting || isSaving || isDeleting || isPreview || disabled}
720-
/>
721-
</div>
722-
723706
{gmailCredentialId && (
724707
<Button
725708
variant='outline'

apps/sim/blocks/blocks/webhook.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ export const WebhookBlock: BlockConfig = {
7878
}),
7979
value: () => 'generic',
8080
},
81+
{
82+
id: 'gmailCredential',
83+
title: 'Gmail Account',
84+
type: 'oauth-input',
85+
layout: 'full',
86+
provider: 'google-email',
87+
serviceId: 'gmail',
88+
requiredScopes: [
89+
'https://www.googleapis.com/auth/gmail.modify',
90+
'https://www.googleapis.com/auth/gmail.labels',
91+
],
92+
placeholder: 'Select Gmail account',
93+
condition: { field: 'webhookProvider', value: 'gmail' },
94+
required: true,
95+
},
8196
{
8297
id: 'webhookConfig',
8398
title: 'Webhook Configuration',

0 commit comments

Comments
 (0)