1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-02 18:17:46 +01:00

Add getUserId and getOptionalUserId rxjs functions (#11741)

This commit is contained in:
Thomas Rittson 2024-10-29 09:51:03 +10:00 committed by GitHub
parent 11f18c478e
commit 3736f6854c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,24 @@ const LOGGED_OUT_INFO: AccountInfo = {
name: undefined,
};
/**
* An rxjs map operator that extracts the UserId from an account, or throws if the account or UserId are null.
*/
export const getUserId = map<{ id: UserId | undefined }, UserId>((account) => {
if (account?.id == null) {
throw new Error("Null account or account ID");
}
return account.id;
});
/**
* An rxjs map operator that extracts the UserId from an account, or returns undefined if the account or UserId are null.
*/
export const getOptionalUserId = map<{ id: UserId | undefined }, UserId | undefined>(
(account) => account?.id ?? undefined,
);
export class AccountServiceImplementation implements InternalAccountService {
private accountsState: GlobalState<Record<UserId, AccountInfo>>;
private activeAccountIdState: GlobalState<UserId | undefined>;