[PM-5455] Listen for Finish Message (#7387)
* Listen for Finish Message * Set Loading to false * Have Type Reflect Possibilities
This commit is contained in:
parent
d3807b09d3
commit
90b794c74d
|
@ -1,7 +1,10 @@
|
|||
import { Component } from "@angular/core";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component";
|
||||
|
||||
import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener";
|
||||
|
||||
@Component({
|
||||
selector: "browser-login-decryption-options",
|
||||
templateUrl: "login-decryption-options.component.html",
|
||||
|
@ -15,4 +18,20 @@ export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsC
|
|||
this.validationService.showError(error);
|
||||
}
|
||||
}
|
||||
|
||||
override async logOut(): Promise<void> {
|
||||
// start listening for "switchAccountFinish" or "doneLoggingOut"
|
||||
const messagePromise = firstValueFrom(postLogoutMessageListener$);
|
||||
super.logOut();
|
||||
// wait for messages
|
||||
const command = await messagePromise;
|
||||
|
||||
// We should be routed/routing very soon but just in case, turn loading back off.
|
||||
this.loading = false;
|
||||
|
||||
// doneLoggingOut already has a message handler that will navigate us
|
||||
if (command === "switchAccountFinish") {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import { filter, map, throwError, timeout } from "rxjs";
|
||||
|
||||
import { fromChromeEvent } from "../../../platform/browser/from-chrome-event";
|
||||
|
||||
/**
|
||||
* Listens to `switchAccountFinish` and `doneLoggingOut` messages and returns which message was heard.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messagePromise = firstValueFrom(postLogoutMessageListener$);
|
||||
* this.messagingService.send("logout");
|
||||
* const message = await messagePromise;
|
||||
* ```
|
||||
*/
|
||||
export const postLogoutMessageListener$ = fromChromeEvent<
|
||||
[message?: { command: "switchAccountFinish" | "doneLoggingOut" }]
|
||||
>(chrome.runtime.onMessage).pipe(
|
||||
map(([message]) => message?.command),
|
||||
filter((command) => command === "switchAccountFinish" || command === "doneLoggingOut"),
|
||||
timeout({
|
||||
first: 60_000,
|
||||
with: () => throwError(() => new Error("Did not receive message from logout.")),
|
||||
}),
|
||||
);
|
Loading…
Reference in New Issue