Skip to content

Commit

Permalink
🧑‍💻 (forge) Make credentials in fetch function optionnal
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 30, 2024
1 parent 49c1c0e commit 988e752
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions apps/builder/src/features/forge/api/fetchSelectItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export const fetchSelectItems = authenticatedProcedure
input: { workspaceId, integrationId, fetcherId, options },
ctx: { user },
}) => {
if (!options.credentialsId) return { items: [] }

const workspace = await prisma.workspace.findFirst({
where: { id: workspaceId },
select: {
Expand All @@ -31,16 +29,18 @@ export const fetchSelectItems = authenticatedProcedure
userId: true,
},
},
credentials: {
where: {
id: options.credentialsId,
},
select: {
id: true,
data: true,
iv: true,
},
},
credentials: options.credentialsId
? {
where: {
id: options.credentialsId,
},
select: {
id: true,
data: true,
iv: true,
},
}
: undefined,
},
})

Expand All @@ -50,11 +50,11 @@ export const fetchSelectItems = authenticatedProcedure
message: 'No workspace found',
})

const credentials = workspace.credentials.at(0)

if (!credentials) return { items: [] }
const credentials = workspace.credentials?.at(0)

const credentialsData = await decrypt(credentials.data, credentials.iv)
const credentialsData = credentials
? await decrypt(credentials.data, credentials.iv)
: undefined

const blockDef = forgedBlocks[integrationId]

Expand All @@ -67,7 +67,8 @@ export const fetchSelectItems = authenticatedProcedure

return {
items: await fetcher.fetch({
credentials: credentialsData,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
credentials: credentialsData as any,
options,
}),
}
Expand Down

0 comments on commit 988e752

Please sign in to comment.