Skip to content

Commit

Permalink
PM-8113 - TwoFactorAuthComponent - some progress on strict TS conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredSnider-Bitwarden committed Jan 13, 2025
1 parent 2dc94df commit 22a82be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
29 changes: 19 additions & 10 deletions libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ import {
export class TwoFactorAuthComponent implements OnInit, OnDestroy {
loading = true;

token = "";
token: string | undefined = undefined;
remember = false;
orgSsoIdentifier: string = null;
orgSsoIdentifier: string | undefined = undefined;
inSsoFlow = false;

providers = TwoFactorProviders;
Expand All @@ -104,7 +104,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {

title = "";

formPromise: Promise<any>;
formPromise: Promise<any> | undefined;

submitForm = async () => {
await this.submit();
Expand Down Expand Up @@ -137,7 +137,10 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {

async ngOnInit() {
this.inSsoFlow = this.activatedRoute.snapshot.queryParamMap.get("sso") === "true";
this.orgSsoIdentifier = this.activatedRoute.snapshot.queryParamMap.get("identifier");

this.orgSsoIdentifier =
this.activatedRoute.snapshot.queryParamMap.get("identifier") ?? undefined;

this.listenFor2faSessionTimeout();

if (this.twoFactorAuthComponentService.shouldCheckForWebauthnResponseOnInit()) {
Expand All @@ -149,8 +152,13 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
await this.setTitleByTwoFactorProviderType();

this.form.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((value) => {
this.token = value.token;
this.remember = value.remember;
if (value.token) {
this.token = value.token;
}

if (value.remember) {
this.remember = value.remember;
}
});

await this.twoFactorAuthComponentService.extendPopupWidthIfRequired?.(
Expand Down Expand Up @@ -215,7 +223,6 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
try {
this.formPromise = this.loginStrategyService.logInTwoFactor(
new TokenTwoFactorRequest(this.selectedProviderType, this.token, this.remember),
null,
);
const authResult: AuthResult = await this.formPromise;
this.logService.info("Successfully submitted two factor token");
Expand Down Expand Up @@ -293,7 +300,9 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
// Save off the OrgSsoIdentifier for use in the TDE flows
// - TDE login decryption options component
// - Browser SSO on extension open
await this.ssoLoginService.setActiveUserOrganizationSsoIdentifier(this.orgSsoIdentifier);
if (this.orgSsoIdentifier !== undefined) {
await this.ssoLoginService.setActiveUserOrganizationSsoIdentifier(this.orgSsoIdentifier);
}

// note: this flow affects both TDE & standard users
if (this.isForcePasswordResetRequired(authResult)) {
Expand Down Expand Up @@ -387,7 +396,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
await this.router.navigate(["login-initiated"]);
}

private async handleChangePasswordRequired(orgIdentifier: string) {
private async handleChangePasswordRequired(orgIdentifier: string | undefined) {
await this.router.navigate(["set-password"], {
queryParams: {
identifier: orgIdentifier,
Expand All @@ -414,7 +423,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
return forceResetReasons.includes(authResult.forcePasswordReset);
}

private async handleForcePasswordReset(orgIdentifier: string) {
private async handleForcePasswordReset(orgIdentifier: string | undefined) {
await this.router.navigate(["update-temp-password"], {
queryParams: {
identifier: orgIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class LoginStrategyServiceAbstraction {
logInTwoFactor: (
twoFactor: TokenTwoFactorRequest,
// TODO: PM-15162 - deprecate captchaResponse
captchaResponse: string,
captchaResponse?: string,
) => Promise<AuthResult>;
/**
* Creates a master key from the provided master password and email.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {

async logInTwoFactor(
twoFactor: TokenTwoFactorRequest,
captchaResponse: string,
captchaResponse?: string,
): Promise<AuthResult> {
if (!(await this.isSessionValid())) {
throw new Error(this.i18nService.t("sessionTimeout"));
Expand Down

0 comments on commit 22a82be

Please sign in to comment.