From 18d84bd429f3100d81ab70a27bbe0e4b047bd8b4 Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Wed, 8 May 2024 17:24:18 -0400 Subject: [PATCH] PM-7392 - Logout callback should simply pass along the LogoutReason instead of handling it - let each client's message listener handle it. --- .../src/services/jslib-services.module.ts | 67 ++----------------- 1 file changed, 7 insertions(+), 60 deletions(-) diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index d0b4f25277..e36769cc4a 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1,5 +1,5 @@ import { ErrorHandler, LOCALE_ID, NgModule } from "@angular/core"; -import { firstValueFrom, Subject } from "rxjs"; +import { Subject } from "rxjs"; import { AuthRequestServiceAbstraction, @@ -118,7 +118,6 @@ import { DefaultBillingAccountProfileStateService } from "@bitwarden/common/bill import { BillingApiService } from "@bitwarden/common/billing/services/billing-api.service"; import { OrganizationBillingService } from "@bitwarden/common/billing/services/organization-billing.service"; import { PaymentMethodWarningsService } from "@bitwarden/common/billing/services/payment-method-warnings.service"; -import { ClientType } from "@bitwarden/common/enums"; import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/platform/abstractions/app-id.service"; import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service"; import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config-api.service.abstraction"; @@ -236,7 +235,7 @@ import { SyncNotifierService } from "@bitwarden/common/vault/services/sync/sync- import { SyncService } from "@bitwarden/common/vault/services/sync/sync.service"; import { TotpService } from "@bitwarden/common/vault/services/totp.service"; import { VaultSettingsService } from "@bitwarden/common/vault/services/vault-settings/vault-settings.service"; -import { ToastOptions, ToastService } from "@bitwarden/components"; +import { ToastService } from "@bitwarden/components"; import { ImportApiService, ImportApiServiceAbstraction, @@ -321,65 +320,13 @@ const safeProviders: SafeProvider[] = [ safeProvider({ provide: LOGOUT_CALLBACK, useFactory: - ( - messagingService: MessagingServiceAbstraction, - toastService: ToastService, - i18nService: I18nServiceAbstraction, - platformUtilsService: PlatformUtilsServiceAbstraction, - ) => + (messagingService: MessagingServiceAbstraction) => async (logoutReason: LogoutReason, userId?: string) => { - const isDesktop = platformUtilsService.getClientType() === ClientType.Desktop; - - let toastOptions: ToastOptions; - switch (logoutReason) { - case "sessionExpired": { - toastOptions = { - variant: "warning", - title: i18nService.t("loggedOut"), - message: i18nService.t("loginExpired"), - }; - break; - } - case "accessTokenUnableToBeDecrypted": { - toastOptions = { - variant: "error", - title: i18nService.t("loggedOut"), - message: i18nService.t("accessTokenUnableToBeDecrypted"), - }; - break; - } - case "refreshTokenSecureStorageRetrievalFailure": { - toastOptions = { - variant: "error", - title: i18nService.t("loggedOut"), - message: i18nService.t("refreshTokenSecureStorageRetrievalFailure"), - }; - break; - } - default: { - toastOptions = { - variant: "error", - title: i18nService.t("loggedOut"), - message: i18nService.t("loggedOutDesc"), - }; - break; - } - } - - const activeToast = toastService.showToast(toastOptions); - if (isDesktop) { - // Since desktop has process reload on logout, we need to wait for the toast to be hidden before triggering the logout. - await firstValueFrom(activeToast.onHidden); - } - - return Promise.resolve(messagingService.send("logout", { userId: userId })); + return Promise.resolve( + messagingService.send("logout", { logoutReason: logoutReason, userId: userId }), + ); }, - deps: [ - MessagingServiceAbstraction, - ToastService, - I18nServiceAbstraction, - PlatformUtilsServiceAbstraction, - ], + deps: [MessagingServiceAbstraction], }), safeProvider({ provide: LOCKED_CALLBACK,