mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
* Handle switch messaging TODO: handle loading state for account switcher * Async updates required for state * Fallback to email for current account avatar * Await un-awaited promises * Remove unnecessary Prune Prune was getting confused in browser and deleting memory in browser on account switch. This method isn't needed since logout already removes memory data, which is the condition for pruning * Fix temp password in browser * Use direct memory access until data is serializable Safari uses a different message object extraction than firefox/chrome and is removing `UInt8Array`s. Until all data passed into StorageService is guaranteed serializable, we need to use direct access in state service * Reload badge and context menu on switch * Gracefully switch account as they log out. * Maintain location on account switch * Remove unused state definitions * Prefer null for state undefined can be misinterpreted to indicate a value has not been set. * Hack: structured clone in memory storage We are currently getting dead objects on account switch due to updating the object in the foreground state service. However, the storage service is owned by the background. This structured clone hack ensures that all objects stored in memory are owned by the appropriate context * Null check nullable values active account can be null, so we should include null safety in the equality * Correct background->foreground switch command * Already providing background memory storage * Handle connection and clipboard on switch account * Prefer strict equal * Ensure structuredClone is available to jsdom This is a deficiency in jsdom -- https://github.com/jsdom/jsdom/issues/3363 -- structured clone is well supported. * Fixup types in faker class
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { Observable } from "rxjs";
|
|
|
|
import { UserId } from "../../types/guid";
|
|
import { AuthenticationStatus } from "../enums/authentication-status";
|
|
|
|
/**
|
|
* 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 = {
|
|
status: AuthenticationStatus;
|
|
email: string;
|
|
name: string | undefined;
|
|
};
|
|
|
|
export function accountInfoEqual(a: AccountInfo, b: AccountInfo) {
|
|
return a?.status === b?.status && a?.email === b?.email && a?.name === b?.name;
|
|
}
|
|
|
|
export abstract class AccountService {
|
|
accounts$: Observable<Record<UserId, AccountInfo>>;
|
|
activeAccount$: Observable<{ id: UserId | undefined } & AccountInfo>;
|
|
accountLock$: Observable<UserId>;
|
|
accountLogout$: Observable<UserId>;
|
|
/**
|
|
* 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 `accounts$` observable with the new account status.
|
|
* Also emits the `accountLock$` or `accountLogout$` observable if the status is `Locked` or `LoggedOut` respectively.
|
|
* @param userId
|
|
* @param status
|
|
*/
|
|
abstract setAccountStatus(userId: UserId, status: AuthenticationStatus): 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;
|
|
}
|