Wrap verification code deletion and sync recording in a transaction

Ensures recordExternalDbSyncDeletion and verificationCode.delete are
atomic, consistent with all other deletion helpers in the codebase.
This commit is contained in:
Bilal Godil 2026-03-19 13:27:58 -07:00
parent 60e9b8685a
commit 2971b655ff

View File

@ -277,25 +277,27 @@ export function createVerificationCodeHandler<
const { project, branchId } = parseProjectBranchCombo(revokeOptions);
const tenancy = await getSoleTenancyFromProjectBranch(project.id, branchId);
// Record deletion for external DB sync if this is a TEAM_INVITATION code
if (options.type === 'TEAM_INVITATION') {
await recordExternalDbSyncDeletion(globalPrismaClient, {
tableName: "VerificationCode_TEAM_INVITATION",
tenancyId: tenancy.id,
verificationCodeProjectId: project.id,
verificationCodeBranchId: branchId,
verificationCodeId: revokeOptions.id,
});
}
await globalPrismaClient.$transaction(async (tx) => {
// Record deletion for external DB sync if this is a TEAM_INVITATION code
if (options.type === 'TEAM_INVITATION') {
await recordExternalDbSyncDeletion(tx, {
tableName: "VerificationCode_TEAM_INVITATION",
tenancyId: tenancy.id,
verificationCodeProjectId: project.id,
verificationCodeBranchId: branchId,
verificationCodeId: revokeOptions.id,
});
}
await globalPrismaClient.verificationCode.delete({
where: {
projectId_branchId_id: {
projectId: project.id,
branchId,
id: revokeOptions.id,
await tx.verificationCode.delete({
where: {
projectId_branchId_id: {
projectId: project.id,
branchId,
id: revokeOptions.id,
},
},
},
});
});
},
async validateCode(tenancyIdAndCode: string) {