Skip to content

Commit

Permalink
PM-8113 - TwoFactorAuthWebAuthnComponent - satisfy strict typescript …
Browse files Browse the repository at this point in the history
…reqs.
  • Loading branch information
JaredSnider-Bitwarden committed Jan 13, 2025
1 parent 13d0d0d commit 2dc94df
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-p
import { WebAuthnIFrame } from "@bitwarden/common/auth/webauthn-iframe";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import {
ButtonModule,
Expand Down Expand Up @@ -49,7 +50,7 @@ export class TwoFactorAuthWebAuthnComponent implements OnInit, OnDestroy {
webAuthnReady = false;
webAuthnNewTab = false;
webAuthnSupported = false;
webAuthnIframe: WebAuthnIFrame = null;
webAuthnIframe: WebAuthnIFrame | undefined = undefined;

constructor(
protected i18nService: I18nService,
Expand All @@ -60,14 +61,19 @@ export class TwoFactorAuthWebAuthnComponent implements OnInit, OnDestroy {
protected route: ActivatedRoute,
private toastService: ToastService,
private twoFactorAuthWebAuthnComponentService: TwoFactorAuthWebAuthnComponentService,
private logService: LogService,
) {
this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win);
this.webAuthnNewTab = this.twoFactorAuthWebAuthnComponentService.shouldOpenWebAuthnInNewTab();
}

async ngOnInit(): Promise<void> {
if (this.route.snapshot.paramMap.has("webAuthnResponse")) {
this.token.emit(this.route.snapshot.paramMap.get("webAuthnResponse"));
const webAuthnResponse = this.route.snapshot.paramMap.get("webAuthnResponse");

if (webAuthnResponse != null) {
this.token.emit(webAuthnResponse);
}
}

if (this.win != null && this.webAuthnSupported) {
Expand Down Expand Up @@ -109,9 +115,14 @@ export class TwoFactorAuthWebAuthnComponent implements OnInit, OnDestroy {
}

async authWebAuthn() {
const providerData = (await this.twoFactorService.getProviders()).get(
TwoFactorProviderType.WebAuthn,
);
const providers = await this.twoFactorService.getProviders();

if (providers == null) {
this.logService.error("No 2FA providers found. Unable to authenticate with WebAuthn.");
return;
}

const providerData = providers?.get(TwoFactorProviderType.WebAuthn);

if (!this.webAuthnSupported || this.webAuthnIframe == null) {
return;
Expand Down

0 comments on commit 2dc94df

Please sign in to comment.