Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Delete integration auth upon integration deletion if no other integrations share the same auth

Tuan Dangee0c79d018a1
diff --git a/backend/src/services/integration/integration-service.ts b/backend/src/services/integration/integration-service.ts
index 5bf412c9be..a3c4c84db7 100644
--- a/backend/src/services/integration/integration-service.ts
+++ b/backend/src/services/integration/integration-service.ts
@@ -146,7 +146,27 @@ export const integrationServiceFactory = ({
);
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.Integrations);
- const deletedIntegration = await integrationDAL.deleteById(id);
+ const deletedIntegration = await integrationDAL.transaction(async (tx) => {
+ // delete integration
+ const deletedIntegrationResult = await integrationDAL.deleteById(id, tx);
+
+ // check if there are other integrations that share the same integration auth
+ const integrations = await integrationDAL.find(
+ {
+ integrationAuthId: integration.integrationAuthId
+ },
+ tx
+ );
+
+ if (integrations.length === 0) {
+ // no other integration shares the same integration auth
+ // -> delete the integration auth
+ await integrationAuthDAL.deleteById(integration.integrationAuthId, tx);
+ }
+
+ return deletedIntegrationResult;
+ });
+
return { ...integration, ...deletedIntegration };
};