diff --git a/services/libs/data-access-layer/src/organizations/base.ts b/services/libs/data-access-layer/src/organizations/base.ts index a24cac29bb..a638938364 100644 --- a/services/libs/data-access-layer/src/organizations/base.ts +++ b/services/libs/data-access-layer/src/organizations/base.ts @@ -450,7 +450,8 @@ export async function findOrCreateOrganization( integrationId?: string, throttleUpdatedAt = false, ): Promise { - const verifiedIdentities = data.identities ? data.identities.filter((i) => i.verified) : [] + data.identities = data.identities ?? [] + let verifiedIdentities = data.identities.filter((i) => i.verified) if (verifiedIdentities.length === 0 && !data.displayName) { const message = `Missing organization identity or displayName while creating/updating organization!` @@ -471,6 +472,16 @@ export async function findOrCreateOrganization( data.identities = data.identities.filter((i) => i.value !== undefined) + // Re-derive after normalization may have set domain identity values to undefined + verifiedIdentities = data.identities.filter((i) => i.verified) + + if (verifiedIdentities.length === 0 && !data.displayName) { + log.debug( + 'Organization has no valid verified identities after domain normalization and no displayName, skipping.', + ) + return undefined + } + let existing // find existing org by sent verified identities for (const identity of verifiedIdentities) {