diff --git a/apps/web/src/app/auth/organization-invite/accept-organization.service.ts b/apps/web/src/app/auth/organization-invite/accept-organization.service.ts index e43023c37d7..d1ffa61f6a9 100644 --- a/apps/web/src/app/auth/organization-invite/accept-organization.service.ts +++ b/apps/web/src/app/auth/organization-invite/accept-organization.service.ts @@ -32,17 +32,17 @@ import { OrganizationInvite } from "./organization-invite"; // We're storing the organization invite for 2 reasons: // 1. If the org requires a MP policy check, we need to keep track that the user has already been redirected when they return. // 2. The MP policy check happens on login/register flows, we need to store the token to retrieve the policies then. -export const ORGANIZATION_INVITE = new KeyDefinition( +export const ORGANIZATION_INVITE = new KeyDefinition( ORGANIZATION_INVITE_DISK, "organizationInvite", { - deserializer: (invite) => OrganizationInvite.fromJSON(invite), + deserializer: (invite) => (invite ? OrganizationInvite.fromJSON(invite) : null), }, ); @Injectable() export class AcceptOrganizationInviteService { - private organizationInvitationState: GlobalState; + private organizationInvitationState: GlobalState; private orgNameSubject: BehaviorSubject = new BehaviorSubject(null); private policyCache: Policy[]; @@ -66,7 +66,7 @@ export class AcceptOrganizationInviteService { } /** Returns the currently stored organization invite */ - async getOrganizationInvite(): Promise { + async getOrganizationInvite(): Promise { return await firstValueFrom(this.organizationInvitationState.state$); } diff --git a/apps/web/src/app/auth/organization-invite/organization-invite.ts b/apps/web/src/app/auth/organization-invite/organization-invite.ts index 9a0bbf83348..ec90fe96d5e 100644 --- a/apps/web/src/app/auth/organization-invite/organization-invite.ts +++ b/apps/web/src/app/auth/organization-invite/organization-invite.ts @@ -11,11 +11,19 @@ export class OrganizationInvite { organizationUserId: string; token: string; - static fromJSON(json: Jsonify) { + static fromJSON(json: Jsonify): OrganizationInvite | null { + if (json == null) { + return null; + } + return Object.assign(new OrganizationInvite(), json); } - static fromParams(params: Params): OrganizationInvite { + static fromParams(params: Params): OrganizationInvite | null { + if (params == null) { + return null; + } + return Object.assign(new OrganizationInvite(), { email: params.email, initOrganization: params.initOrganization?.toLocaleLowerCase() === "true", diff --git a/libs/auth/src/common/services/login-strategies/login-strategy.state.ts b/libs/auth/src/common/services/login-strategies/login-strategy.state.ts index 90fcd89913f..5dc03755050 100644 --- a/libs/auth/src/common/services/login-strategies/login-strategy.state.ts +++ b/libs/auth/src/common/services/login-strategies/login-strategy.state.ts @@ -36,7 +36,7 @@ export const CACHE_EXPIRATION_KEY = new KeyDefinition( * foreground instance to send out the notification. * TODO: Move to Auth Request service. */ -export const AUTH_REQUEST_PUSH_NOTIFICATION_KEY = new KeyDefinition( +export const AUTH_REQUEST_PUSH_NOTIFICATION_KEY = new KeyDefinition( LOGIN_STRATEGY_MEMORY, "authRequestPushNotification", { diff --git a/libs/common/src/auth/services/device-trust.service.implementation.ts b/libs/common/src/auth/services/device-trust.service.implementation.ts index 51461e653b1..b02ff114489 100644 --- a/libs/common/src/auth/services/device-trust.service.implementation.ts +++ b/libs/common/src/auth/services/device-trust.service.implementation.ts @@ -28,13 +28,18 @@ import { } from "../models/request/update-devices-trust.request"; /** Uses disk storage so that the device key can persist after log out and tab removal. */ -export const DEVICE_KEY = new UserKeyDefinition(DEVICE_TRUST_DISK_LOCAL, "deviceKey", { - deserializer: (deviceKey) => SymmetricCryptoKey.fromJSON(deviceKey) as DeviceKey, - clearOn: [], // Device key is needed to log back into device, so we can't clear it automatically during lock or logout -}); +export const DEVICE_KEY = new UserKeyDefinition( + DEVICE_TRUST_DISK_LOCAL, + "deviceKey", + { + deserializer: (deviceKey) => + deviceKey ? (SymmetricCryptoKey.fromJSON(deviceKey) as DeviceKey) : null, + clearOn: [], // Device key is needed to log back into device, so we can't clear it automatically during lock or logout + }, +); /** Uses disk storage so that the shouldTrustDevice bool can persist across login. */ -export const SHOULD_TRUST_DEVICE = new UserKeyDefinition( +export const SHOULD_TRUST_DEVICE = new UserKeyDefinition( DEVICE_TRUST_DISK_LOCAL, "shouldTrustDevice", { diff --git a/libs/common/src/auth/services/key-connector.service.ts b/libs/common/src/auth/services/key-connector.service.ts index 6b81844afb4..a70bbb6ffb0 100644 --- a/libs/common/src/auth/services/key-connector.service.ts +++ b/libs/common/src/auth/services/key-connector.service.ts @@ -29,7 +29,7 @@ import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user import { SetKeyConnectorKeyRequest } from "../models/request/set-key-connector-key.request"; import { IdentityTokenResponse } from "../models/response/identity-token.response"; -export const USES_KEY_CONNECTOR = new UserKeyDefinition( +export const USES_KEY_CONNECTOR = new UserKeyDefinition( KEY_CONNECTOR_DISK, "usesKeyConnector", { @@ -38,7 +38,7 @@ export const USES_KEY_CONNECTOR = new UserKeyDefinition( }, ); -export const CONVERT_ACCOUNT_TO_KEY_CONNECTOR = new UserKeyDefinition( +export const CONVERT_ACCOUNT_TO_KEY_CONNECTOR = new UserKeyDefinition( KEY_CONNECTOR_DISK, "convertAccountToKeyConnector", {