From 1e80c4335f6981adc655c99cb91e92dddd68abc6 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Wed, 9 Feb 2022 12:42:16 -0500 Subject: [PATCH] [bug] Resolve several regression issues (#1302) * [bug] Ensure accounts logging out in the background doesn't impact active account ui The main issue here: inactive accounts with a logout timeout actually log out the active account" is fixed by pulling in jslib. These changes are for some asthetic issues I noticed, where inactive accounts logging out still fires a switchAccount event, which causes a loading spinner to appear and a sync that redraws the vault. * Only load if the account being logged out is the active account: * Replaced any calls to `stateService.activeAccount.getValue` with references to `this.activeUserId`, since we subscribe to that in the component now. * Only send a "switchAccount" method if the active user before a clean and after a clean don't match * [bug] Ensure default vault timeout is set to On Restart We dont override the StateMigrationService instance that is injected in desktop, so it is not aware of desktop defaults. This results in fresh accounts having a "Never" timeout action insteads of "On Restart" * Use the correct StateMigrationService instance * update jslib --- jslib | 2 +- src/app/app.component.ts | 40 ++++++++++++++++++-------------------- src/app/services.module.ts | 14 +++++++++++++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/jslib b/jslib index 8cb02994..c282ef85 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 8cb029947bff7dda54a45483403c3f505fa3e6bc +Subproject commit c282ef8575eecf696d9153435ed3ca4b7dc949d5 diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e2d07231..297015d4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -165,7 +165,7 @@ export class AppComponent implements OnInit { this.router.navigate(["login"]); break; case "logout": - this.loading = true; + this.loading = message.userId == null || message.userId === this.activeUserId; await this.logOut(!!message.expired, message.userId); this.loading = false; break; @@ -449,28 +449,25 @@ export class AppComponent implements OnInit { } private async logOut(expired: boolean, userId?: string) { - if (!userId) { - userId = await this.stateService.getUserId(); - } - + const userBeingLoggedOut = await this.stateService.getUserId({ userId: userId }); await Promise.all([ - this.eventService.uploadEvents(userId), - this.syncService.setLastSync(new Date(0), userId), - this.tokenService.clearToken(userId), - this.cryptoService.clearKeys(userId), - this.settingsService.clear(userId), - this.cipherService.clear(userId), - this.folderService.clear(userId), - this.collectionService.clear(userId), - this.passwordGenerationService.clear(userId), - this.vaultTimeoutService.clear(userId), - this.policyService.clear(userId), + this.eventService.uploadEvents(userBeingLoggedOut), + this.syncService.setLastSync(new Date(0), userBeingLoggedOut), + this.tokenService.clearToken(userBeingLoggedOut), + this.cryptoService.clearKeys(userBeingLoggedOut), + this.settingsService.clear(userBeingLoggedOut), + this.cipherService.clear(userBeingLoggedOut), + this.folderService.clear(userBeingLoggedOut), + this.collectionService.clear(userBeingLoggedOut), + this.passwordGenerationService.clear(userBeingLoggedOut), + this.vaultTimeoutService.clear(userBeingLoggedOut), + this.policyService.clear(userBeingLoggedOut), this.keyConnectorService.clear(), ]); - await this.stateService.setBiometricLocked(true, { userId: userId }); + await this.stateService.setBiometricLocked(true, { userId: userBeingLoggedOut }); - if (userId == null || userId === (await this.stateService.getUserId())) { + if (userBeingLoggedOut === this.activeUserId) { this.searchService.clearIndex(); this.authService.logOut(async () => { if (expired) { @@ -483,11 +480,12 @@ export class AppComponent implements OnInit { }); } - await this.stateService.clean({ userId: userId }); + const preLogoutActiveUserId = this.activeUserId; + await this.stateService.clean({ userId: userBeingLoggedOut }); - if (this.stateService.activeAccount.getValue() == null) { + if (this.activeUserId == null) { this.router.navigate(["login"]); - } else { + } else if (preLogoutActiveUserId !== this.activeUserId) { this.messagingService.send("switchAccount"); } diff --git a/src/app/services.module.ts b/src/app/services.module.ts index f240093f..f5dd79a8 100644 --- a/src/app/services.module.ts +++ b/src/app/services.module.ts @@ -49,6 +49,7 @@ import { Account } from "../models/account"; import { GlobalState } from "jslib-common/models/domain/globalState"; import { StateFactory } from "jslib-common/factories/stateFactory"; +import { StateMigrationService } from "jslib-common/services/stateMigration.service"; export function initFactory( window: Window, @@ -200,6 +201,19 @@ export function initFactory( StateMigrationServiceAbstraction, ], }, + { + provide: StateMigrationServiceAbstraction, + useFactory: ( + storageService: StorageServiceAbstraction, + secureStorageService: StorageServiceAbstraction + ) => + new StateMigrationService( + storageService, + secureStorageService, + new StateFactory(GlobalState, Account) + ), + deps: [StorageServiceAbstraction, "SECURE_STORAGE"], + }, ], }) export class ServicesModule {}