Skip to content

Commit d70a5d4

Browse files
committed
backfill improvements
1 parent 93826cb commit d70a5d4

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

apps/sim/app/api/credentials/route.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export async function GET(request: NextRequest) {
184184
}
185185

186186
if (lookupCredentialId) {
187-
const [row] = await db
187+
let [row] = await db
188188
.select({
189189
id: credential.id,
190190
displayName: credential.displayName,
@@ -195,6 +195,24 @@ export async function GET(request: NextRequest) {
195195
.where(and(eq(credential.id, lookupCredentialId), eq(credential.workspaceId, workspaceId)))
196196
.limit(1)
197197

198+
if (!row) {
199+
;[row] = await db
200+
.select({
201+
id: credential.id,
202+
displayName: credential.displayName,
203+
type: credential.type,
204+
providerId: credential.providerId,
205+
})
206+
.from(credential)
207+
.where(
208+
and(
209+
eq(credential.accountId, lookupCredentialId),
210+
eq(credential.workspaceId, workspaceId)
211+
)
212+
)
213+
.limit(1)
214+
}
215+
198216
return NextResponse.json({ credential: row ?? null })
199217
}
200218

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export function CredentialSelector({
133133
if (!response.ok || cancelled) return
134134
const data = await response.json()
135135
if (!cancelled && data.credential?.displayName) {
136+
if (data.credential.id !== selectedId) {
137+
setStoreValue(data.credential.id)
138+
}
136139
setInaccessibleCredentialName(data.credential.displayName)
137140
}
138141
} catch {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export function ToolCredentialSelector({
109109
if (!response.ok || cancelled) return
110110
const data = await response.json()
111111
if (!cancelled && data.credential?.displayName) {
112+
if (data.credential.id !== selectedId) {
113+
onChange(data.credential.id)
114+
}
112115
setInaccessibleCredentialName(data.credential.displayName)
113116
}
114117
} catch {

packages/db/migrations/0155_nebulous_rocket_raccoon.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ oauth_creds AS (
145145
'cred_' || md5(wua.workspace_id || ':' || a.id) AS id,
146146
wua.workspace_id,
147147
'oauth'::"credential_type",
148-
'Default ' || COALESCE(pn.sname, a.provider_id) || ' Credential',
148+
COALESCE(u.name, 'User') || '''s ' || COALESCE(pn.sname, a.provider_id),
149149
a.provider_id,
150150
a.id,
151151
a.user_id,
152152
now(),
153153
now()
154154
FROM "account" a
155155
INNER JOIN workspace_user_access wua ON wua.user_id = a.user_id
156+
INNER JOIN "user" u ON u.id = a.user_id
156157
LEFT JOIN provider_names pn ON pn.pid = a.provider_id
157158
WHERE a.provider_id != 'credential'
158159
ON CONFLICT DO NOTHING

0 commit comments

Comments
 (0)