[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
This commit is contained in:
Addison Beck 2022-02-09 12:42:16 -05:00 committed by addison
parent 89b167a9a1
commit 828fcc1896
3 changed files with 34 additions and 22 deletions

2
jslib

@ -1 +1 @@
Subproject commit e0cc754d6fe962a5e7eae6d1dead8b44606d4853
Subproject commit 4604547690f42c0b8e1d30730cf47f560ff8457e

View File

@ -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;
@ -451,28 +451,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) {
@ -485,11 +482,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");
}

View File

@ -50,6 +50,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,
@ -201,6 +202,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 {}