[PM-8316] Fix account switcher on vault logout timeout (#10653)

* Fix account switcher on logged out account on startup

* Undo space removal

* Add additional checks for null values

* Fix account switching on timeout on browser

* Fix linting

* Fix broken init in browser
This commit is contained in:
Bernd Schoolmann 2024-09-05 11:24:27 +02:00 committed by GitHub
parent fdd2c774c6
commit 196729fe94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View File

@ -1267,6 +1267,18 @@ export default class MainBackground {
); );
} }
// If the user is logged out, switch to the next account
const active = await firstValueFrom(this.accountService.activeAccount$);
if (active != null) {
const authStatus = await firstValueFrom(
this.authService.authStatuses$.pipe(map((statuses) => statuses[active.id])),
);
if (authStatus === AuthenticationStatus.LoggedOut) {
const nextUpAccount = await firstValueFrom(this.accountService.nextUpAccount$);
await this.switchAccount(nextUpAccount?.id);
}
}
await this.initOverlayAndTabsBackground(); await this.initOverlayAndTabsBackground();
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {

View File

@ -1,6 +1,6 @@
import { animate, state, style, transition, trigger } from "@angular/animations"; import { animate, state, style, transition, trigger } from "@angular/animations";
import { ConnectedPosition } from "@angular/cdk/overlay"; import { ConnectedPosition } from "@angular/cdk/overlay";
import { Component } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { combineLatest, firstValueFrom, map, Observable, switchMap } from "rxjs"; import { combineLatest, firstValueFrom, map, Observable, switchMap } from "rxjs";
@ -51,7 +51,7 @@ type InactiveAccount = ActiveAccount & {
]), ]),
], ],
}) })
export class AccountSwitcherComponent { export class AccountSwitcherComponent implements OnInit {
activeAccount$: Observable<ActiveAccount | null>; activeAccount$: Observable<ActiveAccount | null>;
inactiveAccounts$: Observable<{ [userId: string]: InactiveAccount }>; inactiveAccounts$: Observable<{ [userId: string]: InactiveAccount }>;
authStatus = AuthenticationStatus; authStatus = AuthenticationStatus;
@ -151,6 +151,24 @@ export class AccountSwitcherComponent {
); );
} }
async ngOnInit() {
const active = await firstValueFrom(this.accountService.activeAccount$);
if (active == null) {
return;
}
const authStatus = await firstValueFrom(
this.authService.authStatuses$.pipe(map((statuses) => statuses[active.id])),
);
if (authStatus === AuthenticationStatus.LoggedOut) {
const nextUpAccount = await firstValueFrom(this.accountService.nextUpAccount$);
if (nextUpAccount != null) {
await this.switch(nextUpAccount.id);
} else {
await this.addAccount();
}
}
}
toggle() { toggle() {
this.isOpen = !this.isOpen; this.isOpen = !this.isOpen;
} }