1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 22:33:35 +00:00

Ensure that initialization and migration only run once (#631)

This commit is contained in:
Daniel James Smith
2022-01-24 20:37:52 +01:00
committed by GitHub
parent e5cc3de46d
commit af7da0e942

View File

@@ -58,6 +58,8 @@ export class StateService<TAccount extends Account = Account>
protected state: State<TAccount> = new State<TAccount>(); protected state: State<TAccount> = new State<TAccount>();
private hasBeenInited: boolean = false;
constructor( constructor(
protected storageService: StorageService, protected storageService: StorageService,
protected secureStorageService: StorageService, protected secureStorageService: StorageService,
@@ -67,11 +69,16 @@ export class StateService<TAccount extends Account = Account>
) {} ) {}
async init(): Promise<void> { async init(): Promise<void> {
if (this.hasBeenInited) {
return;
}
if (await this.stateMigrationService.needsMigration()) { if (await this.stateMigrationService.needsMigration()) {
await this.stateMigrationService.migrate(); await this.stateMigrationService.migrate();
} }
await this.initAccountState(); await this.initAccountState();
this.hasBeenInited = true;
} }
async initAccountState() { async initAccountState() {