From c282ef8575eecf696d9153435ed3ca4b7dc949d5 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Wed, 9 Feb 2022 12:15:20 -0500 Subject: [PATCH] [bug] Fix logout timeout action for inactive accounts (#660) * [bug] Fix logout timeout action for inactive accounts * Pass userId in to the logout callback parameter to the vaultTimeoutService. The message handle in desktop already expects this. * Set lastActive on account login, and null it on account deauthentication. This prevents an issue where newly logged in accounts immediatly time out due to inactivity. * Add userId to locked callbacks * Add userId to log out callback --- angular/src/services/jslib-services.module.ts | 3 ++- common/src/services/state.service.ts | 2 ++ common/src/services/vaultTimeout.service.ts | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/angular/src/services/jslib-services.module.ts b/angular/src/services/jslib-services.module.ts index 2e2245a2b8..6770ce1478 100644 --- a/angular/src/services/jslib-services.module.ts +++ b/angular/src/services/jslib-services.module.ts @@ -313,7 +313,8 @@ import { StateFactory } from "jslib-common/factories/stateFactory"; keyConnectorService, stateService, null, - async () => messagingService.send("logout", { expired: false }) + async (userId?: string) => + messagingService.send("logout", { expired: false, userId: userId }) ), deps: [ CipherServiceAbstraction, diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 80f5a81120..5c5be3b209 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -121,6 +121,7 @@ export class StateService< await this.storageService.save(keys.authenticatedAccounts, this.state.authenticatedAccounts); this.state.accounts[account.profile.userId] = account; await this.scaffoldNewAccountStorage(account); + await this.setLastActive(new Date().getTime(), { userId: account.profile.userId }); await this.setActiveUser(account.profile.userId); this.activeAccount.next(account.profile.userId); } @@ -2437,6 +2438,7 @@ export class StateService< protected async deAuthenticateAccount(userId: string) { await this.setAccessToken(null, { userId: userId }); + await this.setLastActive(null, { userId: userId }); const index = this.state.authenticatedAccounts.indexOf(userId); if (index > -1) { this.state.authenticatedAccounts.splice(index, 1); diff --git a/common/src/services/vaultTimeout.service.ts b/common/src/services/vaultTimeout.service.ts index 544e6bc238..e0fa81158d 100644 --- a/common/src/services/vaultTimeout.service.ts +++ b/common/src/services/vaultTimeout.service.ts @@ -29,7 +29,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { private policyService: PolicyService, private keyConnectorService: KeyConnectorService, private stateService: StateService, - private lockedCallback: () => Promise = null, + private lockedCallback: (userId?: string) => Promise = null, private loggedOutCallback: (userId?: string) => Promise = null ) {} @@ -87,7 +87,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { (pinSet[0] && (await this.stateService.getDecryptedPinProtected()) != null) || pinSet[1]; if (!pinLock && !(await this.isBiometricLockSet())) { - await this.logOut(); + await this.logOut(userId); } } @@ -110,7 +110,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { this.messagingService.send("locked", { userId: userId }); if (this.lockedCallback != null) { - await this.lockedCallback(); + await this.lockedCallback(userId); } } @@ -198,6 +198,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { private async executeTimeoutAction(userId: string): Promise { const timeoutAction = await this.stateService.getVaultTimeoutAction({ userId: userId }); - timeoutAction === "logOut" ? await this.logOut() : await this.lock(true, userId); + timeoutAction === "logOut" ? await this.logOut(userId) : await this.lock(true, userId); } }