From b0020c278b45ce3a2255769b554a836cbfe2e1f5 Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:38:54 -0700 Subject: [PATCH] make userId a component property on ChangePasswordComponent, and pass userId down to child InputPasswordComponent --- .../change-password.component.html | 1 + .../change-password.component.ts | 14 ++++++-------- .../input-password/input-password.component.ts | 17 ++++++++--------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/auth/src/angular/change-password/change-password.component.html b/libs/auth/src/angular/change-password/change-password.component.html index 455461cddad..f6c93509d5b 100644 --- a/libs/auth/src/angular/change-password/change-password.component.html +++ b/libs/auth/src/angular/change-password/change-password.component.html @@ -1,6 +1,7 @@ ; @@ -58,11 +58,11 @@ export class ChangePasswordComponent implements OnInit { this.userkeyRotationV2 = await this.configService.getFeatureFlag(FeatureFlag.UserKeyRotationV2); const activeAccount = await firstValueFrom(this.accountService.activeAccount$); - const userId = activeAccount.id; - this.email = activeAccount.email; + this.userId = activeAccount?.id; + this.email = activeAccount?.email; this.masterPasswordPolicyOptions = await firstValueFrom( - this.policyService.masterPasswordPolicyOptions$(userId), + this.policyService.masterPasswordPolicyOptions$(this.userId), ); } @@ -133,8 +133,6 @@ export class ChangePasswordComponent implements OnInit { await this.syncService.fullSync(true); } - const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); - let newMasterKeyEncryptedUserKey: [UserKey, EncString] | null = null; const userKey = await this.keyService.getUserKey(); @@ -160,11 +158,11 @@ export class ChangePasswordComponent implements OnInit { // we need to save this for local masterkey verification during rotation await this.masterPasswordService.setMasterKeyHash( passwordInputResult.newLocalMasterKeyHash, - userId as UserId, + this.userId as UserId, ); await this.masterPasswordService.setMasterKey( passwordInputResult.newMasterKey, - userId as UserId, + this.userId as UserId, ); return this.updateKey(passwordInputResult.newPassword); }); diff --git a/libs/auth/src/angular/input-password/input-password.component.ts b/libs/auth/src/angular/input-password/input-password.component.ts index 2d878383d95..6b50021130d 100644 --- a/libs/auth/src/angular/input-password/input-password.component.ts +++ b/libs/auth/src/angular/input-password/input-password.component.ts @@ -6,7 +6,6 @@ import { FormGroup, FormControl, } from "@angular/forms"; -import { firstValueFrom } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { @@ -17,12 +16,12 @@ import { AuditService } from "@bitwarden/common/abstractions/audit.service"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { HashPurpose } from "@bitwarden/common/platform/enums"; import { Utils } from "@bitwarden/common/platform/misc/utils"; +import { UserId } from "@bitwarden/common/types/guid"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { AsyncActionsModule, @@ -97,6 +96,7 @@ export class InputPasswordComponent implements OnInit { @Input({ required: true }) inputPasswordFlow!: InputPasswordFlow; @Input({ required: true }) email!: string; + @Input({ required: true }) userId!: UserId; @Input() loading = false; @Input() masterPasswordPolicyOptions: MasterPasswordPolicyOptions | null = null; @@ -235,7 +235,10 @@ export class InputPasswordComponent implements OnInit { this.inputPasswordFlow === InputPasswordFlow.ChangeExistingPasswordAndOptionallyRotateAccountEncryptionKey ) { - const currentPasswordIsCorrect = await this.verifyCurrentPassword(currentPassword); + const currentPasswordIsCorrect = await this.verifyCurrentPassword( + currentPassword, + this.userId, + ); if (!currentPasswordIsCorrect) { return; } @@ -321,9 +324,7 @@ export class InputPasswordComponent implements OnInit { /** * Returns true if the current password is correct, false otherwise */ - private async verifyCurrentPassword(currentPassword: string): Promise { - const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); - + private async verifyCurrentPassword(currentPassword: string, userId: UserId): Promise { const currentMasterKey = await this.keyService.makeMasterKey( currentPassword, this.email.trim().toLowerCase(), @@ -423,9 +424,7 @@ export class InputPasswordComponent implements OnInit { const rotateUserKey = rotateUserKeyCtrl?.value; if (rotateUserKey) { - const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); - - const ciphers = await this.cipherService.getAllDecrypted(activeUserId); + const ciphers = await this.cipherService.getAllDecrypted(this.userId); let hasOldAttachments = false; if (ciphers != null) { for (let i = 0; i < ciphers.length; i++) {