Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PS-1514] Do not subscribe to activeAccount-observable and execute load asynchronously #3608

13 changes: 2 additions & 11 deletions apps/browser/src/popup/accounts/lock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { LogService } from "@bitwarden/common/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service";
import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus";
Expand All @@ -28,8 +27,6 @@ export class LockComponent extends BaseLockComponent {

biometricError: string;
pendingBiometric = false;
authenicatedUrl = "/tabs/current";
unAuthenicatedUrl = "/update-temp-password";

constructor(
router: Router,
Expand All @@ -45,8 +42,7 @@ export class LockComponent extends BaseLockComponent {
logService: LogService,
keyConnectorService: KeyConnectorService,
ngZone: NgZone,
private authService: AuthService,
private syncService: SyncService
private authService: AuthService
) {
super(
router,
Expand All @@ -63,17 +59,12 @@ export class LockComponent extends BaseLockComponent {
keyConnectorService,
ngZone
);

this.successRoute = "/tabs/current";
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
}

async ngOnInit() {
await super.ngOnInit();
await this.syncService.fullSync(true);

const forcePasswordReset = await this.stateService.getForcePasswordReset();
this.successRoute = forcePasswordReset === true ? this.unAuthenicatedUrl : this.authenicatedUrl;

const disableAutoBiometricsPrompt =
(await this.stateService.getDisableAutoBiometricsPrompt()) ?? true;

Expand Down
11 changes: 1 addition & 10 deletions apps/desktop/src/app/accounts/lock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { LogService } from "@bitwarden/common/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service";

Expand All @@ -25,8 +24,6 @@ const BroadcasterSubscriptionId = "LockComponent";
})
export class LockComponent extends BaseLockComponent {
private deferFocus: boolean = null;
authenicatedUrl = "vault";
unAuthenicatedUrl = "update-temp-password";

constructor(
router: Router,
Expand All @@ -43,8 +40,7 @@ export class LockComponent extends BaseLockComponent {
private broadcasterService: BroadcasterService,
ngZone: NgZone,
logService: LogService,
keyConnectorService: KeyConnectorService,
private syncService: SyncService
keyConnectorService: KeyConnectorService
) {
super(
router,
Expand All @@ -67,11 +63,6 @@ export class LockComponent extends BaseLockComponent {
await super.ngOnInit();
const autoPromptBiometric = !(await this.stateService.getNoAutoPromptBiometrics());

await this.syncService.fullSync(true);
Copy link
Member

@Hinton Hinton Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like just deprecating this function with a disclaimer, NEVER CALL, considering it's both network and resource intensive!


const forcePasswordReset = await this.stateService.getForcePasswordReset();
this.successRoute = forcePasswordReset === true ? this.unAuthenicatedUrl : this.authenicatedUrl;

// eslint-disable-next-line rxjs-angular/prefer-takeuntil
this.route.queryParams.subscribe((params) => {
if (this.supportsBiometric && params.promptBiometric && autoPromptBiometric) {
Expand Down
21 changes: 13 additions & 8 deletions libs/angular/src/components/lock.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Directive, NgZone, OnDestroy, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { Subscription } from "rxjs";
import { take } from "rxjs/operators";
import { Subject } from "rxjs";
import { concatMap, take, takeUntil } from "rxjs/operators";

import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
Expand Down Expand Up @@ -41,7 +41,7 @@ export class LockComponent implements OnInit, OnDestroy {
private invalidPinAttempts = 0;
private pinSet: [boolean, boolean];

private activeAccountSubscription: Subscription;
private destroy$ = new Subject<void>();

constructor(
protected router: Router,
Expand All @@ -60,14 +60,19 @@ export class LockComponent implements OnInit, OnDestroy {
) {}

async ngOnInit() {
// eslint-disable-next-line rxjs/no-async-subscribe
this.activeAccountSubscription = this.stateService.activeAccount$.subscribe(async () => {
await this.load();
});
this.stateService.activeAccount$
.pipe(
concatMap(async () => {
await this.load();
}),
takeUntil(this.destroy$)
)
.subscribe();
}

ngOnDestroy() {
this.activeAccountSubscription.unsubscribe();
this.destroy$.next();
this.destroy$.complete();
}

async submit() {
Expand Down