Skip to content

Commit 7899a71

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(oauth): fail closed when reconnect target disappears
1 parent dd48b47 commit 7899a71

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/credential-selector/credential-selector.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useCallback, useMemo, useState } from 'react'
3+
import { useCallback, useEffect, useMemo, useState } from 'react'
44
import { Button, Combobox, type ComboboxOptionGroup } from '@sim/emcn'
55
import { Key, SquareArrowUpRight } from '@sim/emcn/icons'
66
import { useParams } from 'next/navigation'
@@ -209,6 +209,13 @@ export function CredentialSelector({
209209
!isPreview &&
210210
!credentialsLoading
211211

212+
useEffect(() => {
213+
if (showOAuthModal && selectedId && !selectedCredential) {
214+
consumeOAuthReturnContext()
215+
setShowOAuthModal(false)
216+
}
217+
}, [showOAuthModal, selectedId, selectedCredential])
218+
212219
const handleSelect = useCallback(
213220
(credentialId: string) => {
214221
if (isPreview) return
@@ -497,7 +504,7 @@ export function CredentialSelector({
497504
/>
498505
)}
499506

500-
{showOAuthModal && (
507+
{showOAuthModal && selectedCredential && (
501508
<ConnectOAuthModal
502509
mode='reauthorize'
503510
open={showOAuthModal}
@@ -515,16 +522,12 @@ export function CredentialSelector({
515522
// A reauthorize must return to the authorization server that issued
516523
// the credential — deriving it from the service id would send a
517524
// sandbox user to production, where they cannot sign in at all.
518-
providerId={selectedCredential?.provider ?? effectiveProviderId}
519-
reconnectTarget={
520-
selectedCredential
521-
? {
522-
workspaceId,
523-
credentialId: selectedCredential.id,
524-
displayName: selectedCredential.name,
525-
}
526-
: undefined
527-
}
525+
providerId={selectedCredential.provider}
526+
reconnectTarget={{
527+
workspaceId,
528+
credentialId: selectedCredential.id,
529+
displayName: selectedCredential.name,
530+
}}
528531
/>
529532
)}
530533

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/tools/credential-selector.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useCallback, useMemo, useRef, useState } from 'react'
3+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
44
import { Button, Combobox } from '@sim/emcn'
55
import { SquareArrowUpRight } from '@sim/emcn/icons'
66
import { useParams } from 'next/navigation'
@@ -147,6 +147,13 @@ export function ToolCredentialSelector({
147147
const needsUpdate =
148148
hasSelection && missingRequiredScopes.length > 0 && !disabled && !credentialsLoading
149149

150+
useEffect(() => {
151+
if (showOAuthModal && selectedId && !selectedCredential) {
152+
consumeOAuthReturnContext()
153+
setShowOAuthModal(false)
154+
}
155+
}, [showOAuthModal, selectedId, selectedCredential])
156+
150157
const handleSelect = useCallback(
151158
(credentialId: string) => {
152159
onChange(credentialId)
@@ -279,7 +286,7 @@ export function ToolCredentialSelector({
279286
/>
280287
)}
281288

282-
{showOAuthModal && (
289+
{showOAuthModal && selectedCredential && (
283290
<ConnectOAuthModal
284291
mode='reauthorize'
285292
open={showOAuthModal}
@@ -297,16 +304,12 @@ export function ToolCredentialSelector({
297304
// A reauthorize must return to the authorization server that issued
298305
// the credential — deriving it from the service id would send a
299306
// sandbox user to production, where they cannot sign in at all.
300-
providerId={selectedCredential?.provider ?? effectiveProviderId}
301-
reconnectTarget={
302-
selectedCredential
303-
? {
304-
workspaceId,
305-
credentialId: selectedCredential.id,
306-
displayName: selectedCredential.name,
307-
}
308-
: undefined
309-
}
307+
providerId={selectedCredential.provider}
308+
reconnectTarget={{
309+
workspaceId,
310+
credentialId: selectedCredential.id,
311+
displayName: selectedCredential.name,
312+
}}
310313
/>
311314
)}
312315
</div>

0 commit comments

Comments
 (0)