From 72f8debc507f8e547a9e6dc9684b6e298febe620 Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Tue, 8 Apr 2025 16:48:58 -0700 Subject: [PATCH] update typing --- .../change-password.component.ts | 6 +++++- .../input-password/input-password.component.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 10 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 f360795d2fd..c883a18c56c 100644 --- a/libs/auth/src/angular/change-password/change-password.component.ts +++ b/libs/auth/src/angular/change-password/change-password.component.ts @@ -34,7 +34,7 @@ import { PasswordInputResult } from "../input-password/password-input-result"; export class ChangePasswordComponent implements OnInit { @Input() inputPasswordFlow: InputPasswordFlow = InputPasswordFlow.ChangePassword; - activeAccount?: Account; + activeAccount: Account | null = null; email?: string; userId?: UserId; masterPasswordPolicyOptions?: MasterPasswordPolicyOptions; @@ -62,6 +62,10 @@ export class ChangePasswordComponent implements OnInit { this.userId = this.activeAccount?.id; this.email = this.activeAccount?.email; + if (this.userId == null) { + throw new Error("UserId cannot be null"); + } + this.masterPasswordPolicyOptions = await firstValueFrom( this.policyService.masterPasswordPolicyOptions$(this.userId), ); 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 0351237177a..c6d5ca71fca 100644 --- a/libs/auth/src/angular/input-password/input-password.component.ts +++ b/libs/auth/src/angular/input-password/input-password.component.ts @@ -34,12 +34,7 @@ import { ToastService, Translation, } from "@bitwarden/components"; -import { - DEFAULT_KDF_CONFIG, - KdfConfig, - KdfConfigService, - KeyService, -} from "@bitwarden/key-management"; +import { KdfConfig, KdfConfigService, KeyService } from "@bitwarden/key-management"; // FIXME: remove `src` and fix import // eslint-disable-next-line no-restricted-imports @@ -108,7 +103,7 @@ export class InputPasswordComponent implements OnInit { protected secondaryButtonTextStr: string = ""; protected InputPasswordFlow = InputPasswordFlow; - private kdfConfig: KdfConfig = DEFAULT_KDF_CONFIG; + private kdfConfig: KdfConfig | null = null; private minHintLength = 0; protected maxHintLength = 50; protected minPasswordLength = Utils.minimumPasswordLength; @@ -240,6 +235,7 @@ export class InputPasswordComponent implements OnInit { const currentPasswordIsCorrect = await this.verifyCurrentPassword( currentPassword, this.userId, + this.kdfConfig, ); if (!currentPasswordIsCorrect) { return; @@ -326,11 +322,15 @@ export class InputPasswordComponent implements OnInit { /** * Returns true if the current password is correct, false otherwise */ - private async verifyCurrentPassword(currentPassword: string, userId: UserId): Promise { + private async verifyCurrentPassword( + currentPassword: string, + userId: UserId, + kdfConfig: KdfConfig, + ): Promise { const currentMasterKey = await this.keyService.makeMasterKey( currentPassword, this.email.trim().toLowerCase(), - this.kdfConfig, + kdfConfig, ); const decryptedUserKey = await this.masterPasswordService.decryptUserKeyWithMasterKey(