From 06273f3b2afdd2a19a5b775a85d20dd0124fe58f Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Mon, 17 Mar 2025 10:02:33 -0500 Subject: [PATCH] Revert changes to v1 components --- .../src/auth/popup/two-factor-v1.component.ts | 48 +------------------ .../src/auth/two-factor-v1.component.ts | 3 -- .../src/app/auth/two-factor-v1.component.ts | 3 -- .../two-factor-v1.component.spec.ts | 8 ---- .../components/two-factor-v1.component.ts | 6 --- 5 files changed, 2 insertions(+), 66 deletions(-) diff --git a/apps/browser/src/auth/popup/two-factor-v1.component.ts b/apps/browser/src/auth/popup/two-factor-v1.component.ts index 3dff2308517..884e42bf73a 100644 --- a/apps/browser/src/auth/popup/two-factor-v1.component.ts +++ b/apps/browser/src/auth/popup/two-factor-v1.component.ts @@ -7,7 +7,6 @@ import { filter, first, takeUntil } from "rxjs/operators"; import { TwoFactorComponentV1 as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor-v1.component"; import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; -import { TwoFactorFormCacheService } from "@bitwarden/auth/angular"; import { LoginStrategyServiceAbstraction, LoginEmailServiceAbstraction, @@ -68,7 +67,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn toastService: ToastService, @Inject(WINDOW) protected win: Window, private browserMessagingApi: ZonedMessageListenerService, - protected twoFactorFormCacheService: TwoFactorFormCacheService, ) { super( loginStrategyService, @@ -90,7 +88,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn masterPasswordService, accountService, toastService, - twoFactorFormCacheService, ); this.onSuccessfulLogin = async () => { // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. @@ -130,18 +127,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn return; } - // Load form data from cache if available - const cachedData = await this.twoFactorFormCacheService.getFormData(); - if (cachedData?.token !== undefined) { - this.token = cachedData.token; - } - if (cachedData?.remember !== undefined) { - this.remember = cachedData.remember; - } - if (cachedData?.selectedProviderType !== undefined) { - this.selectedProviderType = cachedData.selectedProviderType; - } - await super.ngOnInit(); if (this.selectedProviderType == null) { return; @@ -155,8 +140,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn if ( this.selectedProviderType === TwoFactorProviderType.Email && - BrowserPopupUtils.inPopup(window) && - !(await this.configService.getFeatureFlag(FeatureFlag.PM9115_TwoFactorFormPersistence)) + BrowserPopupUtils.inPopup(window) ) { const confirmed = await this.dialogService.openSimpleDialog({ title: { key: "warning" }, @@ -203,15 +187,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn super.ngOnDestroy(); } - async anotherMethod() { - // Save form data to cache before navigating to another method - await this.twoFactorFormCacheService.saveFormData({ - token: this.token, - remember: this.remember, - selectedProviderType: this.selectedProviderType, - emailSent: this.selectedProviderType === TwoFactorProviderType.Email, - }); - + anotherMethod() { const sso = this.route.snapshot.queryParamMap.get("sso") === "true"; if (sso) { @@ -281,24 +257,4 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn encodeURIComponent(JSON.stringify(duoHandOffMessage)); this.platformUtilsService.launchUri(launchUrl); } - - // Override the doSubmit to clear cached data on successful login - async doSubmit() { - await super.doSubmit(); - await this.twoFactorFormCacheService.clearFormData(); - } - - /** - * Save the current form state to cache when inputs change - */ - async saveFormData() { - if (this.twoFactorFormCacheService) { - await this.twoFactorFormCacheService.saveFormData({ - token: this.token, - remember: this.remember, - selectedProviderType: this.selectedProviderType, - emailSent: this.selectedProviderType === TwoFactorProviderType.Email, - }); - } - } } diff --git a/apps/desktop/src/auth/two-factor-v1.component.ts b/apps/desktop/src/auth/two-factor-v1.component.ts index a5e01ef32d1..13c7d0a452b 100644 --- a/apps/desktop/src/auth/two-factor-v1.component.ts +++ b/apps/desktop/src/auth/two-factor-v1.component.ts @@ -29,7 +29,6 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { ToastService } from "@bitwarden/components"; -import { DesktopTwoFactorFormCacheService } from "./services/desktop-two-factor-form-cache.service"; import { TwoFactorOptionsComponentV1 } from "./two-factor-options-v1.component"; const BroadcasterSubscriptionId = "TwoFactorComponent"; @@ -69,7 +68,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnDe accountService: AccountService, toastService: ToastService, @Inject(WINDOW) protected win: Window, - twoFactorFormCacheService: DesktopTwoFactorFormCacheService, ) { super( loginStrategyService, @@ -91,7 +89,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnDe masterPasswordService, accountService, toastService, - twoFactorFormCacheService, ); this.onSuccessfulLogin = async () => { // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. diff --git a/apps/web/src/app/auth/two-factor-v1.component.ts b/apps/web/src/app/auth/two-factor-v1.component.ts index 2a896f0ed5f..9a9fab02de3 100644 --- a/apps/web/src/app/auth/two-factor-v1.component.ts +++ b/apps/web/src/app/auth/two-factor-v1.component.ts @@ -7,7 +7,6 @@ import { Subject, takeUntil, lastValueFrom } from "rxjs"; import { TwoFactorComponentV1 as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor-v1.component"; import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; -import { TwoFactorFormCacheService } from "@bitwarden/auth/angular"; import { LoginStrategyServiceAbstraction, LoginEmailServiceAbstraction, @@ -74,7 +73,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn toastService: ToastService, private formBuilder: FormBuilder, @Inject(WINDOW) protected win: Window, - twoFactorFormCacheService: TwoFactorFormCacheService, ) { super( loginStrategyService, @@ -96,7 +94,6 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn masterPasswordService, accountService, toastService, - twoFactorFormCacheService, ); this.onSuccessfulLoginNavigate = this.goAfterLogIn; } diff --git a/libs/angular/src/auth/components/two-factor-v1.component.spec.ts b/libs/angular/src/auth/components/two-factor-v1.component.spec.ts index 32d393b80c9..47075acc758 100644 --- a/libs/angular/src/auth/components/two-factor-v1.component.spec.ts +++ b/libs/angular/src/auth/components/two-factor-v1.component.spec.ts @@ -5,7 +5,6 @@ import { mock, MockProxy } from "jest-mock-extended"; import { BehaviorSubject } from "rxjs"; import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; -import { TwoFactorFormCacheService } from "@bitwarden/auth/angular"; import { LoginStrategyServiceAbstraction, LoginEmailServiceAbstraction, @@ -73,7 +72,6 @@ describe("TwoFactorComponent", () => { let mockMasterPasswordService: FakeMasterPasswordService; let mockAccountService: FakeAccountService; let mockToastService: MockProxy; - let mockTwoFactorFormCacheService: MockProxy; let mockUserDecryptionOpts: { noMasterPassword: UserDecryptionOptions; @@ -110,11 +108,6 @@ describe("TwoFactorComponent", () => { mockAccountService = mockAccountServiceWith(userId); mockToastService = mock(); mockMasterPasswordService = new FakeMasterPasswordService(); - mockTwoFactorFormCacheService = mock(); - - // Setup form cache service mock with necessary observables - mockTwoFactorFormCacheService.isEnabled$.mockReturnValue(new BehaviorSubject(false)); - mockTwoFactorFormCacheService.formData$.mockReturnValue(new BehaviorSubject(null)); mockUserDecryptionOpts = { noMasterPassword: new UserDecryptionOptions({ @@ -197,7 +190,6 @@ describe("TwoFactorComponent", () => { { provide: InternalMasterPasswordServiceAbstraction, useValue: mockMasterPasswordService }, { provide: AccountService, useValue: mockAccountService }, { provide: ToastService, useValue: mockToastService }, - { provide: TwoFactorFormCacheService, useValue: mockTwoFactorFormCacheService }, ], }); diff --git a/libs/angular/src/auth/components/two-factor-v1.component.ts b/libs/angular/src/auth/components/two-factor-v1.component.ts index 9662bd5dd2e..3fda2685f5e 100644 --- a/libs/angular/src/auth/components/two-factor-v1.component.ts +++ b/libs/angular/src/auth/components/two-factor-v1.component.ts @@ -7,7 +7,6 @@ import { firstValueFrom } from "rxjs"; import { first } from "rxjs/operators"; import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; -import { TwoFactorFormCacheService } from "@bitwarden/auth/angular"; import { LoginStrategyServiceAbstraction, LoginEmailServiceAbstraction, @@ -100,7 +99,6 @@ export class TwoFactorComponentV1 extends CaptchaProtectedComponent implements O protected masterPasswordService: InternalMasterPasswordServiceAbstraction, protected accountService: AccountService, protected toastService: ToastService, - protected twoFactorFormCacheService: TwoFactorFormCacheService, ) { super(environmentService, i18nService, platformUtilsService, toastService); @@ -439,10 +437,6 @@ export class TwoFactorComponentV1 extends CaptchaProtectedComponent implements O return; } - if ((await this.twoFactorFormCacheService.getFormData()).emailSent) { - return; - } - if ((await this.loginStrategyService.getEmail()) == null) { this.toastService.showToast({ variant: "error",