1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-7169][PM-5267] Remove auth status from account info (#8539)

* remove active account unlocked from state service

* Remove status from account service `AccountInfo`

* Fixup lingering usages of status

Fixup missed factories

* Fixup account info usage

* fixup CLI build

* Fixup current account type

* Add helper for all auth statuses to auth service

* Fix tests

* Uncomment mistakenly commented code

* Rework logged out account exclusion tests

* Correct test description

* Avoid getters returning observables

* fixup type
This commit is contained in:
Matt Gibson
2024-04-12 02:25:45 -05:00
committed by GitHub
parent c7ea35280d
commit 8d698d9d84
31 changed files with 200 additions and 304 deletions

View File

@@ -1,9 +1,8 @@
import { BehaviorSubject, Observable, map } from "rxjs";
import { BehaviorSubject } from "rxjs";
import { Jsonify, JsonValue } from "type-fest";
import { AccountService } from "../../auth/abstractions/account.service";
import { TokenService } from "../../auth/abstractions/token.service";
import { AuthenticationStatus } from "../../auth/enums/authentication-status";
import { AdminAuthRequestStorable } from "../../auth/models/domain/admin-auth-req-storable";
import { KdfConfig } from "../../auth/models/domain/kdf-config";
import { BiometricKey } from "../../auth/types/biometric-key";
@@ -68,8 +67,6 @@ export class StateService<
protected activeAccountSubject = new BehaviorSubject<string | null>(null);
activeAccount$ = this.activeAccountSubject.asObservable();
activeAccountUnlocked$: Observable<boolean>;
private hasBeenInited = false;
protected isRecoveredSession = false;
@@ -89,13 +86,7 @@ export class StateService<
protected tokenService: TokenService,
private migrationRunner: MigrationRunner,
protected useAccountCache: boolean = true,
) {
this.activeAccountUnlocked$ = this.accountService.activeAccount$.pipe(
map((a) => {
return a?.status === AuthenticationStatus.Unlocked;
}),
);
}
) {}
async init(initOptions: InitOptions = {}): Promise<void> {
// Deconstruct and apply defaults
@@ -151,7 +142,6 @@ export class StateService<
await this.accountService.addAccount(state.activeUserId as UserId, {
name: activeDiskAccount.profile.name,
email: activeDiskAccount.profile.email,
status: AuthenticationStatus.LoggedOut,
});
}
await this.accountService.switchAccount(state.activeUserId as UserId);
@@ -177,16 +167,7 @@ export class StateService<
// TODO: Temporary update to avoid routing all account status changes through account service for now.
// The determination of state should be handled by the various services that control those values.
const token = await this.tokenService.getAccessToken(userId as UserId);
const autoKey = await this.getUserKeyAutoUnlock({ userId: userId });
const accountStatus =
token == null
? AuthenticationStatus.LoggedOut
: autoKey == null
? AuthenticationStatus.Locked
: AuthenticationStatus.Unlocked;
await this.accountService.addAccount(userId as UserId, {
status: accountStatus,
name: diskAccount.profile.name,
email: diskAccount.profile.email,
});
@@ -206,7 +187,6 @@ export class StateService<
await this.setLastActive(new Date().getTime(), { userId: account.profile.userId });
// TODO: Temporary update to avoid routing all account status changes through account service for now.
await this.accountService.addAccount(account.profile.userId as UserId, {
status: AuthenticationStatus.Locked,
name: account.profile.name,
email: account.profile.email,
});
@@ -1406,8 +1386,6 @@ export class StateService<
return state;
});
// TODO: Invert this logic, we should remove accounts based on logged out emit
await this.accountService.setAccountStatus(userId as UserId, AuthenticationStatus.LoggedOut);
}
// settings persist even on reset, and are not affected by this method