1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-03 10:13:31 +00:00

address PR feedback: 'missing null safety check'

This commit is contained in:
rr-bw
2025-11-10 15:03:03 -08:00
parent 8f79c924d5
commit 5b23ff60bf
4 changed files with 32 additions and 2 deletions

View File

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

View File

@@ -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({

View File

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

View File

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