diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index e77ef8d3f07..901d7a9c5cc 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -411,7 +411,8 @@ export class AppComponent implements OnInit, OnDestroy { this.masterPasswordService.forceSetPasswordReason$(message.userId), )) != ForceSetPasswordReason.None; if (locked) { - this.messagingService.send("locked", { userId: message.userId }); + this.modalService.closeAll(); + await this.router.navigate(["lock"]); } else if (forcedPasswordReset) { // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // eslint-disable-next-line @typescript-eslint/no-floating-promises diff --git a/libs/common/src/platform/services/crypto.service.ts b/libs/common/src/platform/services/crypto.service.ts index 61dc6b81ad6..7595d5a3e32 100644 --- a/libs/common/src/platform/services/crypto.service.ts +++ b/libs/common/src/platform/services/crypto.service.ts @@ -174,7 +174,7 @@ export class CryptoService implements CryptoServiceAbstraction { userId ??= await firstValueFrom(this.stateProvider.activeUserId$); masterKey ??= await firstValueFrom(this.masterPasswordService.masterKey$(userId)); - return await this.validateUserKey(masterKey as unknown as UserKey); + return await this.validateUserKey(masterKey as unknown as UserKey, userId); } // TODO: legacy support for user key is no longer needed since we require users to migrate on login @@ -193,9 +193,10 @@ export class CryptoService implements CryptoServiceAbstraction { } async getUserKeyFromStorage(keySuffix: KeySuffixOptions, userId?: UserId): Promise { + userId ??= await firstValueFrom(this.stateProvider.activeUserId$); const userKey = await this.getKeyFromStorage(keySuffix, userId); if (userKey) { - if (!(await this.validateUserKey(userKey))) { + if (!(await this.validateUserKey(userKey, userId))) { this.logService.warning("Invalid key, throwing away stored keys"); await this.clearAllStoredUserKeys(userId); } @@ -663,13 +664,15 @@ export class CryptoService implements CryptoServiceAbstraction { } // ---HELPERS--- - protected async validateUserKey(key: UserKey): Promise { + protected async validateUserKey(key: UserKey, userId: UserId): Promise { if (!key) { return false; } try { - const encPrivateKey = await firstValueFrom(this.activeUserEncryptedPrivateKeyState.state$); + const encPrivateKey = await firstValueFrom( + this.stateProvider.getUserState$(USER_ENCRYPTED_PRIVATE_KEY, userId), + ); if (encPrivateKey == null) { return false; }