[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 GitHub
parent c51b8523b7
commit 1e80c4335f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 22 deletions

2
jslib

@ -1 +1 @@
Subproject commit 8cb029947bff7dda54a45483403c3f505fa3e6bc
Subproject commit c282ef8575eecf696d9153435ed3ca4b7dc949d5

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;
@ -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");
}

View File

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