1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00
Files
browser/libs/common/src/auth/abstractions/account.service.ts
Matt Gibson 8d698d9d84 [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
2024-04-12 09:25:45 +02:00

49 lines
1.4 KiB
TypeScript

import { Observable } from "rxjs";
import { UserId } from "../../types/guid";
/**
* Holds information about an account for use in the AccountService
* if more information is added, be sure to update the equality method.
*/
export type AccountInfo = {
email: string;
name: string | undefined;
};
export function accountInfoEqual(a: AccountInfo, b: AccountInfo) {
return a?.email === b?.email && a?.name === b?.name;
}
export abstract class AccountService {
accounts$: Observable<Record<UserId, AccountInfo>>;
activeAccount$: Observable<{ id: UserId | undefined } & AccountInfo>;
/**
* Updates the `accounts$` observable with the new account data.
* @param userId
* @param accountData
*/
abstract addAccount(userId: UserId, accountData: AccountInfo): Promise<void>;
/**
* updates the `accounts$` observable with the new preferred name for the account.
* @param userId
* @param name
*/
abstract setAccountName(userId: UserId, name: string): Promise<void>;
/**
* updates the `accounts$` observable with the new email for the account.
* @param userId
* @param email
*/
abstract setAccountEmail(userId: UserId, email: string): Promise<void>;
/**
* Updates the `activeAccount$` observable with the new active account.
* @param userId
*/
abstract switchAccount(userId: UserId): Promise<void>;
}
export abstract class InternalAccountService extends AccountService {
abstract delete(): void;
}