diff --git a/apps/browser/src/auth/services/auth-request-answering/extension-auth-request-answering.service.ts b/apps/browser/src/auth/services/auth-request-answering/extension-auth-request-answering.service.ts index a647e870b3c..ab59b1fbaa6 100644 --- a/apps/browser/src/auth/services/auth-request-answering/extension-auth-request-answering.service.ts +++ b/apps/browser/src/auth/services/auth-request-answering/extension-auth-request-answering.service.ts @@ -10,12 +10,14 @@ import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-manageme import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ActionsService } from "@bitwarden/common/platform/actions"; import { ButtonLocation, SystemNotificationEvent, SystemNotificationsService, } from "@bitwarden/common/platform/system-notifications/system-notifications.service"; +import { LogService } from "@bitwarden/logging"; import { UserId } from "@bitwarden/user-core"; export class ExtensionAuthRequestAnsweringService @@ -32,6 +34,8 @@ export class ExtensionAuthRequestAnsweringService private readonly i18nService: I18nService, private readonly platformUtilsService: PlatformUtilsService, private readonly systemNotificationsService: SystemNotificationsService, + private readonly logService: LogService, + private readonly validationService: ValidationService, ) { super( accountService, @@ -63,7 +67,15 @@ export class ExtensionAuthRequestAnsweringService } else { // Create a system notification const accounts = await firstValueFrom(this.accountService.accounts$); - const emailForUser = accounts[userId].email; + const accountInfo = accounts[userId]; + + if (!accountInfo) { + this.logService.error(`Account not found for userId: ${userId}`); + this.validationService.showError(`Account not found for userId: ${userId}`); + return; + } + + const emailForUser = accountInfo.email; await this.systemNotificationsService.create({ id: `${AuthServerNotificationTags.AuthRequest}_${authRequestId}`, // the underscore is an important delimiter. title: this.i18nService.t("accountAccessRequested"), diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index acfe2f755cf..671e73609ec 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -101,6 +101,7 @@ import { AbstractStorageService, ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; +import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ActionsService } from "@bitwarden/common/platform/actions"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection @@ -492,6 +493,8 @@ const safeProviders: SafeProvider[] = [ I18nServiceAbstraction, PlatformUtilsService, SystemNotificationsService, + LogService, + ValidationService, ], }), safeProvider({ diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 3cfec275f42..8686c6241a9 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -90,6 +90,7 @@ import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk- import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; +import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; @@ -489,6 +490,8 @@ const safeProviders: SafeProvider[] = [ MessagingServiceAbstraction, PendingAuthRequestsStateService, I18nServiceAbstraction, + LogService, + ValidationService, ], }), ]; diff --git a/apps/desktop/src/auth/services/auth-request-answering/desktop-auth-request-answering.service.ts b/apps/desktop/src/auth/services/auth-request-answering/desktop-auth-request-answering.service.ts index 69865522481..54565f32494 100644 --- a/apps/desktop/src/auth/services/auth-request-answering/desktop-auth-request-answering.service.ts +++ b/apps/desktop/src/auth/services/auth-request-answering/desktop-auth-request-answering.service.ts @@ -8,6 +8,8 @@ import { PendingAuthRequestsStateService } from "@bitwarden/common/auth/services import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; +import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; +import { LogService } from "@bitwarden/logging"; import { UserId } from "@bitwarden/user-core"; export class DesktopAuthRequestAnsweringService @@ -21,6 +23,8 @@ export class DesktopAuthRequestAnsweringService protected readonly messagingService: MessagingService, protected readonly pendingAuthRequestsState: PendingAuthRequestsStateService, private readonly i18nService: I18nService, + private readonly logService: LogService, + private readonly validationService: ValidationService, ) { super( accountService, @@ -58,7 +62,15 @@ export class DesktopAuthRequestAnsweringService // also create the system notification to notify the user that the dialog is there. if (!userMeetsConditionsToShowApprovalDialog || !isWindowVisible) { const accounts = await firstValueFrom(this.accountService.accounts$); - const emailForUser = accounts[userId].email; + const accountInfo = accounts[userId]; + + if (!accountInfo) { + this.logService.error(`Account not found for userId: ${userId}`); + this.validationService.showError(`Account not found for userId: ${userId}`); + return; + } + + const emailForUser = accountInfo.email; await ipc.auth.loginRequest( this.i18nService.t("accountAccessRequested"), this.i18nService.t("confirmAccessAttempt", emailForUser),