PM-7392 - Logout callback should simply pass along the LogoutReason instead of handling it - let each client's message listener handle it.

This commit is contained in:
Jared Snider 2024-05-08 17:24:18 -04:00
parent 706935098b
commit 18d84bd429
No known key found for this signature in database
GPG Key ID: A149DDD612516286
1 changed files with 7 additions and 60 deletions

View File

@ -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,