diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 0da55cbda5f..124cf6a78d8 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -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(); return new Promise((resolve) => { diff --git a/apps/desktop/src/app/layout/account-switcher.component.ts b/apps/desktop/src/app/layout/account-switcher.component.ts index f641d801b8d..c6dbadade42 100644 --- a/apps/desktop/src/app/layout/account-switcher.component.ts +++ b/apps/desktop/src/app/layout/account-switcher.component.ts @@ -1,6 +1,6 @@ import { animate, state, style, transition, trigger } from "@angular/animations"; import { ConnectedPosition } from "@angular/cdk/overlay"; -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { Router } from "@angular/router"; 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; inactiveAccounts$: Observable<{ [userId: string]: InactiveAccount }>; 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() { this.isOpen = !this.isOpen; }