From 720967475b37d635c18a1eb74bb3702445647b4d Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 16 Nov 2021 19:43:37 +1000 Subject: [PATCH] Update base export component for userVerificationService changes (#552) * Use new try/catch pattern in export.component * Set initial value in VerifyMasterPass component --- angular/src/components/export.component.ts | 5 +++- .../verify-master-password.component.ts | 24 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/angular/src/components/export.component.ts b/angular/src/components/export.component.ts index 8b9372c340..716f9ef05e 100644 --- a/angular/src/components/export.component.ts +++ b/angular/src/components/export.component.ts @@ -69,7 +69,10 @@ export class ExportComponent implements OnInit { } const secret = this.exportForm.get('secret').value; - if (!await this.userVerificationService.verifyUser(secret)) { + try { + await this.userVerificationService.verifyUser(secret); + } catch (e) { + this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), e.message); return; } diff --git a/angular/src/components/verify-master-password.component.ts b/angular/src/components/verify-master-password.component.ts index 658f7f59ae..9d8bca633f 100644 --- a/angular/src/components/verify-master-password.component.ts +++ b/angular/src/components/verify-master-password.component.ts @@ -8,7 +8,6 @@ import { NG_VALUE_ACCESSOR, } from '@angular/forms'; -import { ApiService } from 'jslib-common/abstractions/api.service'; import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service'; @@ -40,17 +39,9 @@ export class VerifyMasterPasswordComponent implements ControlValueAccessor, OnIn async ngOnInit() { this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector(); + this.processChanges(this.secret.value); - this.secret.valueChanges.subscribe(secret => { - if (this.onChange == null) { - return; - } - - this.onChange({ - type: this.usesKeyConnector ? VerificationType.OTP : VerificationType.MasterPassword, - secret: secret, - }); - }); + this.secret.valueChanges.subscribe(secret => this.processChanges(secret)); } async requestOTP() { @@ -80,4 +71,15 @@ export class VerifyMasterPasswordComponent implements ControlValueAccessor, OnIn this.secret.enable(); } } + + private processChanges(secret: string) { + if (this.onChange == null) { + return; + } + + this.onChange({ + type: this.usesKeyConnector ? VerificationType.OTP : VerificationType.MasterPassword, + secret: secret, + }); + } }