From a96ac61d98d281cef49add0d8cf42395e7919e2e Mon Sep 17 00:00:00 2001 From: addison Date: Fri, 5 Nov 2021 11:58:35 -0400 Subject: [PATCH] [bug] Ensure the logout command callback can handle any user in state --- src/app/app.component.ts | 40 +++++++++++++++++++------------------- src/app/services.module.ts | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1ad33a7f..f46abdc9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -145,7 +145,7 @@ export class AppComponent implements OnInit { this.router.navigate(['login']); break; case 'logout': - this.logOut(!!message.expired); + this.logOut(!!message.expired, message.userId); break; case 'lockVault': await this.vaultTimeoutService.lock(true, message.userId); @@ -352,34 +352,34 @@ export class AppComponent implements OnInit { } } - private async logOut(expired: boolean) { - await this.eventService.uploadEvents(); - const userId = await this.stateService.getUserId(); - + private async logOut(expired: boolean, userId?: string) { await Promise.all([ - this.eventService.clearEvents(), - this.syncService.setLastSync(new Date(0)), - this.tokenService.clearToken(), - this.cryptoService.clearKeys(), + 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(), - this.vaultTimeoutService.clear(), + this.passwordGenerationService.clear(userId), + this.vaultTimeoutService.clear(userId), this.policyService.clear(userId), - await this.stateService.purge(), + this.stateService.purge({ userId: userId }), ]); await this.stateService.setBiometricLocked(true); - this.searchService.clearIndex(); - this.authService.logOut(async () => { - if (expired) { - this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'), - this.i18nService.t('loginExpired')); - } - this.router.navigate(['login']); - }); + + if (userId == await this.stateService.getUserId()) { + this.searchService.clearIndex(); + this.authService.logOut(async () => { + if (expired) { + this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'), + this.i18nService.t('loginExpired')); + } + this.router.navigate(['login']); + }); + } } private async recordActivity() { diff --git a/src/app/services.module.ts b/src/app/services.module.ts index 76e1ca4b..8e0410d0 100644 --- a/src/app/services.module.ts +++ b/src/app/services.module.ts @@ -125,7 +125,7 @@ const providerService: ProviderServiceAbstraction = new ProviderService(stateSer const policyService = new PolicyService(stateService, organizationService, apiService); const vaultTimeoutService = new VaultTimeoutService(cipherService, folderService, collectionService, cryptoService, platformUtilsService, messagingService, searchService, tokenService, policyService, stateService, null, - async () => messagingService.send('logout', { expired: false })); + async (userId?: string) => messagingService.send('logout', { userId: userId, expired: false })); const syncService = new SyncService(apiService, settingsService, folderService, cipherService, cryptoService, collectionService, messagingService, policyService, sendService, logService, async (expired: boolean) => messagingService.send('logout', { expired: expired }), stateService, organizationService, providerService);