mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-7535] Remove Uses of getUserId (#10837)
* Remove Uses of `getUserId` * Fix Test
This commit is contained in:
@@ -196,22 +196,23 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
|
||||
async ngOnInit() {
|
||||
this.vaultTimeoutOptions = await this.generateVaultTimeoutOptions();
|
||||
|
||||
this.userHasMasterPassword = await this.userVerificationService.hasMasterPassword();
|
||||
|
||||
this.isWindows = (await this.platformUtilsService.getDevice()) === DeviceType.WindowsDesktop;
|
||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||
this.isLinux = (await this.platformUtilsService.getDevice()) === DeviceType.LinuxDesktop;
|
||||
|
||||
if ((await this.stateService.getUserId()) == null) {
|
||||
if (activeAccount == null || activeAccount.id == null) {
|
||||
return;
|
||||
}
|
||||
this.currentUserEmail = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.email)),
|
||||
);
|
||||
this.currentUserId = (await this.stateService.getUserId()) as UserId;
|
||||
this.userHasMasterPassword = await this.userVerificationService.hasMasterPassword();
|
||||
|
||||
this.isWindows = this.platformUtilsService.getDevice() === DeviceType.WindowsDesktop;
|
||||
|
||||
this.currentUserEmail = activeAccount.email;
|
||||
this.currentUserId = activeAccount.id;
|
||||
|
||||
this.availableVaultTimeoutActions$ = this.refreshTimeoutSettings$.pipe(
|
||||
switchMap(() => this.vaultTimeoutSettingsService.availableVaultTimeoutActions$()),
|
||||
switchMap(() =>
|
||||
this.vaultTimeoutSettingsService.availableVaultTimeoutActions$(activeAccount.id),
|
||||
),
|
||||
);
|
||||
|
||||
// Load timeout policy
|
||||
@@ -236,12 +237,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
}),
|
||||
);
|
||||
|
||||
const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
|
||||
|
||||
// Load initial values
|
||||
this.userHasPinSet = await this.pinService.isPinSet(userId);
|
||||
|
||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||
this.userHasPinSet = await this.pinService.isPinSet(activeAccount.id);
|
||||
|
||||
const initialValues = {
|
||||
vaultTimeout: await firstValueFrom(
|
||||
|
||||
@@ -235,7 +235,8 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
this.modalService.closeAll();
|
||||
if (
|
||||
message.userId == null ||
|
||||
message.userId === (await this.stateService.getUserId())
|
||||
message.userId ===
|
||||
(await firstValueFrom(this.accountService.activeAccount$.pipe(map((a) => a?.id))))
|
||||
) {
|
||||
await this.router.navigate(["lock"]);
|
||||
}
|
||||
@@ -274,9 +275,11 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
await this.openModal<PremiumComponent>(PremiumComponent, this.premiumRef);
|
||||
break;
|
||||
case "showFingerprintPhrase": {
|
||||
const fingerprint = await this.cryptoService.getFingerprint(
|
||||
await this.stateService.getUserId(),
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
const publicKey = await firstValueFrom(this.cryptoService.userPublicKey$(activeUserId));
|
||||
const fingerprint = await this.cryptoService.getFingerprint(activeUserId, publicKey);
|
||||
const dialogRef = FingerprintDialogComponent.open(this.dialogService, { fingerprint });
|
||||
await firstValueFrom(dialogRef.closed);
|
||||
break;
|
||||
|
||||
@@ -201,8 +201,11 @@ export class AccountSwitcherComponent implements OnInit {
|
||||
}): Promise<{ [userId: string]: InactiveAccount }> {
|
||||
const inactiveAccounts: { [userId: string]: InactiveAccount } = {};
|
||||
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
for (const userId in baseAccounts) {
|
||||
if (userId == null || userId === (await this.stateService.getUserId())) {
|
||||
if (userId == null || userId === activeUserId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -461,11 +461,10 @@ describe("LockComponent", () => {
|
||||
});
|
||||
|
||||
describe("canUseBiometric", () => {
|
||||
it("should call getUserId() on stateService", async () => {
|
||||
stateServiceMock.getUserId.mockResolvedValue("userId");
|
||||
it("should call biometric.enabled with current active user", async () => {
|
||||
await component["canUseBiometric"]();
|
||||
|
||||
expect(ipc.keyManagement.biometric.enabled).toHaveBeenCalledWith("userId");
|
||||
expect(ipc.keyManagement.biometric.enabled).toHaveBeenCalledWith(mockUserId);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, NgZone, OnDestroy, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { firstValueFrom, switchMap } from "rxjs";
|
||||
import { firstValueFrom, map, switchMap } from "rxjs";
|
||||
|
||||
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component";
|
||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||
@@ -182,7 +182,7 @@ export class LockComponent extends BaseLockComponent implements OnInit, OnDestro
|
||||
}
|
||||
|
||||
private async canUseBiometric() {
|
||||
const userId = await this.stateService.getUserId();
|
||||
const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(map((a) => a?.id)));
|
||||
return await ipc.keyManagement.biometric.enabled(userId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user