🧑💻 (forge) Make credentials in fetch function optionnal
This commit is contained in:
@ -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: {
|
||||
@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@ -50,11 +50,11 @@ export const fetchSelectItems = authenticatedProcedure
|
||||
message: 'No workspace found',
|
||||
})
|
||||
|
||||
const credentials = workspace.credentials.at(0)
|
||||
const credentials = workspace.credentials?.at(0)
|
||||
|
||||
if (!credentials) return { items: [] }
|
||||
|
||||
const credentialsData = await decrypt(credentials.data, credentials.iv)
|
||||
const credentialsData = credentials
|
||||
? await decrypt(credentials.data, credentials.iv)
|
||||
: undefined
|
||||
|
||||
const blockDef = forgedBlocks[integrationId]
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
}
|
||||
|
Reference in New Issue
Block a user