From 67bc8d591f12975a5da43bab726748ef5e1af689 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Wed, 25 Oct 2023 07:48:34 -0400 Subject: [PATCH] Handle active user not logged in (#6692) This occurs when all users are logged out, we use the last logged in user as the active user to indicate which settings should be loaded by default. --- libs/common/src/platform/services/state.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/common/src/platform/services/state.service.ts b/libs/common/src/platform/services/state.service.ts index c8d45b6d4e..aa8ffb8a6f 100644 --- a/libs/common/src/platform/services/state.service.ts +++ b/libs/common/src/platform/services/state.service.ts @@ -173,7 +173,18 @@ export class StateService< await this.pushAccounts(); this.activeAccountSubject.next(state.activeUserId); // TODO: Temporary update to avoid routing all account status changes through account service for now. + // account service tracks logged out accounts, but State service does not, so we need to add the active account + // if it's not in the accounts list. + if (this.accountsSubject.value[state.activeUserId] == null) { + const activeDiskAccount = await this.getAccountFromDisk({ userId: state.activeUserId }); + this.accountService.addAccount(state.activeUserId as UserId, { + name: activeDiskAccount.profile.name, + email: activeDiskAccount.profile.email, + status: AuthenticationStatus.LoggedOut, + }); + } this.accountService.switchAccount(state.activeUserId as UserId); + // End TODO return state; });