diff --git a/apps/web/src/app/settings/verify-email.component.ts b/apps/web/src/app/settings/verify-email.component.ts index 665bb9975a..c49b377968 100644 --- a/apps/web/src/app/settings/verify-email.component.ts +++ b/apps/web/src/app/settings/verify-email.component.ts @@ -1,9 +1,10 @@ -import { Component } from "@angular/core"; +import { Component, EventEmitter, Output } from "@angular/core"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; +import { TokenService } from "@bitwarden/common/abstractions/token.service"; @Component({ selector: "app-verify-email", @@ -12,25 +13,40 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti export class VerifyEmailComponent { actionPromise: Promise; + @Output() onVerified = new EventEmitter(); + constructor( private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private logService: LogService + private logService: LogService, + private tokenService: TokenService ) {} + async verifyEmail(): Promise { + await this.apiService.refreshIdentityToken(); + if (await this.tokenService.getEmailVerified()) { + this.onVerified.emit(true); + this.platformUtilsService.showToast("success", null, this.i18nService.t("emailVerified")); + return; + } + + await this.apiService.postAccountVerifyEmail(); + this.platformUtilsService.showToast( + "success", + null, + this.i18nService.t("checkInboxForVerification") + ); + } + async send() { if (this.actionPromise != null) { return; } + try { - this.actionPromise = this.apiService.postAccountVerifyEmail(); + this.actionPromise = this.verifyEmail(); await this.actionPromise; - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t("checkInboxForVerification") - ); } catch (e) { this.logService.error(e); } diff --git a/apps/web/src/app/vault/vault.component.html b/apps/web/src/app/vault/vault.component.html index 151354e4dc..1ea77b34b1 100644 --- a/apps/web/src/app/vault/vault.component.html +++ b/apps/web/src/app/vault/vault.component.html @@ -78,7 +78,12 @@ - + +
diff --git a/apps/web/src/app/vault/vault.component.ts b/apps/web/src/app/vault/vault.component.ts index a511d44e36..9f9c0d3780 100644 --- a/apps/web/src/app/vault/vault.component.ts +++ b/apps/web/src/app/vault/vault.component.ts @@ -169,6 +169,10 @@ export class VaultComponent implements OnInit, OnDestroy { ); } + emailVerified(verified: boolean) { + this.showVerifyEmail = !verified; + } + ngOnDestroy() { this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); }