1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-21 16:18:28 +01:00

[PM-5455] Listen for Finish Message (#7387)

* Listen for Finish Message

* Set Loading to false

* Have Type Reflect Possibilities
This commit is contained in:
Justin Baur 2024-01-02 10:05:26 -05:00 committed by GitHub
parent d3807b09d3
commit 90b794c74d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -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(["/"]);
}
}
}

View File

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