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 {}