1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PS-1134] Folder fixes, including revamped auth logic (#3118)

This commit is contained in:
Oscar Hinton
2022-07-18 14:39:12 +02:00
committed by GitHub
parent cd5aef1757
commit fbff2e5f00
11 changed files with 65 additions and 49 deletions

View File

@@ -56,6 +56,7 @@ export class StateService<
{
accounts = new BehaviorSubject<{ [userId: string]: TAccount }>({});
activeAccount = new BehaviorSubject<string>(null);
activeAccountUnlocked = new BehaviorSubject<boolean>(false);
private hasBeenInited = false;
private isRecoveredSession = false;
@@ -70,7 +71,21 @@ export class StateService<
protected stateMigrationService: StateMigrationService,
protected stateFactory: StateFactory<TGlobalState, TAccount>,
protected useAccountCache: boolean = true
) {}
) {
// If the account gets changed, verify the new account is unlocked
this.activeAccount.subscribe(async (userId) => {
if (userId == null && this.activeAccountUnlocked.getValue() == false) {
return;
} else if (userId == null) {
this.activeAccountUnlocked.next(false);
}
// FIXME: This should be refactored into AuthService or a similar service,
// as checking for the existance of the crypto key is a low level
// implementation detail.
this.activeAccountUnlocked.next((await this.getCryptoMasterKey()) != null);
});
}
async init(): Promise<void> {
if (this.hasBeenInited) {
@@ -499,6 +514,15 @@ export class StateService<
account,
this.reconcileOptions(options, await this.defaultInMemoryOptions())
);
if (options.userId == this.activeAccount.getValue()) {
const nextValue = value != null;
// Avoid emitting if we are already unlocked
if (this.activeAccountUnlocked.getValue() != nextValue) {
this.activeAccountUnlocked.next(nextValue);
}
}
}
async getCryptoMasterKeyAuto(options?: StorageOptions): Promise<string> {