From d806ea2d31cc799711744699403b54b240e86ae4 Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:55:07 -0700 Subject: [PATCH] update activeAccount retreival to happen just once --- .../change-password.component.ts | 23 ++++++++++--------- .../input-password.component.ts | 2 -- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libs/auth/src/angular/change-password/change-password.component.ts b/libs/auth/src/angular/change-password/change-password.component.ts index e72193dd40c..f360795d2fd 100644 --- a/libs/auth/src/angular/change-password/change-password.component.ts +++ b/libs/auth/src/angular/change-password/change-password.component.ts @@ -4,7 +4,7 @@ import { firstValueFrom } from "rxjs"; import { ChangePasswordService } from "@bitwarden/auth/common"; 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 { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { MasterPasswordApiService } from "@bitwarden/common/auth/abstractions/master-password-api.service.abstraction"; import { PasswordRequest } from "@bitwarden/common/auth/models/request/password.request"; import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; @@ -34,6 +34,7 @@ import { PasswordInputResult } from "../input-password/password-input-result"; export class ChangePasswordComponent implements OnInit { @Input() inputPasswordFlow: InputPasswordFlow = InputPasswordFlow.ChangePassword; + activeAccount?: Account; email?: string; userId?: UserId; masterPasswordPolicyOptions?: MasterPasswordPolicyOptions; @@ -57,9 +58,9 @@ export class ChangePasswordComponent implements OnInit { async ngOnInit() { this.userkeyRotationV2 = await this.configService.getFeatureFlag(FeatureFlag.UserKeyRotationV2); - const activeAccount = await firstValueFrom(this.accountService.activeAccount$); - this.userId = activeAccount?.id; - this.email = activeAccount?.email; + this.activeAccount = await firstValueFrom(this.accountService.activeAccount$); + this.userId = this.activeAccount?.id; + this.email = this.activeAccount?.email; this.masterPasswordPolicyOptions = await firstValueFrom( this.policyService.masterPasswordPolicyOptions$(this.userId), @@ -86,16 +87,15 @@ export class ChangePasswordComponent implements OnInit { try { if (passwordInputResult.rotateUserKey) { await this.syncService.fullSync(true); - const user = await firstValueFrom(this.accountService.activeAccount$); - if (user == null) { + if (this.activeAccount == null) { throw new Error("User not found"); } await this.changePasswordService.rotateUserKeyMasterPasswordAndEncryptedData( passwordInputResult.currentPassword, passwordInputResult.newPassword, - user, + this.activeAccount, passwordInputResult.newPasswordHint, ); } else { @@ -188,12 +188,13 @@ export class ChangePasswordComponent implements OnInit { } private async updateKey(newPassword: string) { - const user = await firstValueFrom(this.accountService.activeAccount$); - - if (user == null) { + if (this.activeAccount == null) { throw new Error("User not found"); } - await this.changePasswordService.rotateUserKeyAndEncryptedDataLegacy(newPassword, user); + await this.changePasswordService.rotateUserKeyAndEncryptedDataLegacy( + newPassword, + this.activeAccount, + ); } } 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 6b50021130d..a84738d6023 100644 --- a/libs/auth/src/angular/input-password/input-password.component.ts +++ b/libs/auth/src/angular/input-password/input-password.component.ts @@ -15,7 +15,6 @@ import { 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 { 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"; @@ -146,7 +145,6 @@ export class InputPasswordComponent implements OnInit { ); constructor( - private accountService: AccountService, private auditService: AuditService, private cipherService: CipherService, private dialogService: DialogService,