1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

[PM-4090] Fix: Automatic biometric authentication no longer worked (Resolves: #6134) (#6400)

* chore: improve FR localization

* fix: Automatic biometric authentication no longer worked

* chore: add tests for the fixed file

* Revert "chore: improve FR localization"

This reverts commit 957cbee9b3.

* tests: fixes after resolved conflicts

* chore(review): delete fluffy-spoon from tests

* chore(review): resolve warnings from tests
This commit is contained in:
Thomas Cauquil
2023-12-13 19:16:22 +01:00
committed by GitHub
parent 3c7f369e40
commit bc61212969
2 changed files with 417 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
import { Component, NgZone } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { switchMap } from "rxjs";
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
@@ -31,6 +32,8 @@ const BroadcasterSubscriptionId = "LockComponent";
export class LockComponent extends BaseLockComponent {
private deferFocus: boolean = null;
protected biometricReady = false;
private biometricAsked = false;
private autoPromptBiometric = false;
constructor(
router: Router,
@@ -78,23 +81,14 @@ export class LockComponent extends BaseLockComponent {
async ngOnInit() {
await super.ngOnInit();
const autoPromptBiometric = !(await this.stateService.getDisableAutoBiometricsPrompt());
this.autoPromptBiometric = !(await this.stateService.getDisableAutoBiometricsPrompt());
this.biometricReady = await this.canUseBiometric();
await this.displayBiometricUpdateWarning();
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
this.route.queryParams.subscribe((params) => {
setTimeout(async () => {
if (!params.promptBiometric || !this.supportsBiometric || !autoPromptBiometric) {
return;
}
this.delayedAskForBiometric(500);
this.route.queryParams.pipe(switchMap((params) => this.delayedAskForBiometric(500, params)));
if (await ipc.platform.isWindowVisible()) {
this.unlockBiometric();
}
}, 1000);
});
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
this.ngZone.run(() => {
switch (message.command) {
@@ -128,6 +122,23 @@ export class LockComponent extends BaseLockComponent {
this.showPassword = false;
}
private async delayedAskForBiometric(delay: number, params?: any) {
await new Promise((resolve) => setTimeout(resolve, delay));
if (params && !params.promptBiometric) {
return;
}
if (!this.supportsBiometric || !this.autoPromptBiometric || this.biometricAsked) {
return;
}
this.biometricAsked = true;
if (await ipc.platform.isWindowVisible()) {
this.unlockBiometric();
}
}
private async canUseBiometric() {
const userId = await this.stateService.getUserId();
return await ipc.platform.biometric.enabled(userId);