From eadd8c656ddb4cd13a2e91437d12afe5299e278e Mon Sep 17 00:00:00 2001 From: Maciej Zieniuk Date: Thu, 27 Mar 2025 18:21:30 +0000 Subject: [PATCH] type safety improvements --- .../key-connector/services/key-connector.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/common/src/key-management/key-connector/services/key-connector.service.ts b/libs/common/src/key-management/key-connector/services/key-connector.service.ts index 546b991132e..974c6b2ee17 100644 --- a/libs/common/src/key-management/key-connector/services/key-connector.service.ts +++ b/libs/common/src/key-management/key-connector/services/key-connector.service.ts @@ -92,6 +92,12 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { async migrateUser(userId: UserId) { const organization = await this.getManagingOrganization(userId); + if (organization == null) { + throw new Error( + "[Key Connector service] No key connector enabled organization found, aborting user migration to key connector.", + ); + } + const masterKey = await firstValueFrom(this.masterPasswordService.masterKey$(userId)); const keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.encKeyB64); @@ -188,7 +194,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { throw new Error("Key Connector error"); } - private findManagingOrganization(organizations: Organization[]) { + private findManagingOrganization(organizations: Organization[]): Organization | undefined { return organizations.find( (o) => o.keyConnectorEnabled &&