1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

[PM-8868] only deserialize org invite if not nullish (#9644)

* only deserialize org invite if not nullish

* add null check to OrganizationInvite init methods

* PR feedback
This commit is contained in:
Jake Fink
2024-06-25 15:00:27 -04:00
committed by GitHub
parent 41e1d91558
commit d7bf0fe536
5 changed files with 27 additions and 14 deletions

View File

@@ -32,17 +32,17 @@ import { OrganizationInvite } from "./organization-invite";
// We're storing the organization invite for 2 reasons: // 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. // 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. // 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<OrganizationInvite>( export const ORGANIZATION_INVITE = new KeyDefinition<OrganizationInvite | null>(
ORGANIZATION_INVITE_DISK, ORGANIZATION_INVITE_DISK,
"organizationInvite", "organizationInvite",
{ {
deserializer: (invite) => OrganizationInvite.fromJSON(invite), deserializer: (invite) => (invite ? OrganizationInvite.fromJSON(invite) : null),
}, },
); );
@Injectable() @Injectable()
export class AcceptOrganizationInviteService { export class AcceptOrganizationInviteService {
private organizationInvitationState: GlobalState<OrganizationInvite>; private organizationInvitationState: GlobalState<OrganizationInvite | null>;
private orgNameSubject: BehaviorSubject<string> = new BehaviorSubject<string>(null); private orgNameSubject: BehaviorSubject<string> = new BehaviorSubject<string>(null);
private policyCache: Policy[]; private policyCache: Policy[];
@@ -66,7 +66,7 @@ export class AcceptOrganizationInviteService {
} }
/** Returns the currently stored organization invite */ /** Returns the currently stored organization invite */
async getOrganizationInvite(): Promise<OrganizationInvite> { async getOrganizationInvite(): Promise<OrganizationInvite | null> {
return await firstValueFrom(this.organizationInvitationState.state$); return await firstValueFrom(this.organizationInvitationState.state$);
} }

View File

@@ -11,11 +11,19 @@ export class OrganizationInvite {
organizationUserId: string; organizationUserId: string;
token: string; token: string;
static fromJSON(json: Jsonify<OrganizationInvite>) { static fromJSON(json: Jsonify<OrganizationInvite>): OrganizationInvite | null {
if (json == null) {
return null;
}
return Object.assign(new OrganizationInvite(), json); 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(), { return Object.assign(new OrganizationInvite(), {
email: params.email, email: params.email,
initOrganization: params.initOrganization?.toLocaleLowerCase() === "true", initOrganization: params.initOrganization?.toLocaleLowerCase() === "true",

View File

@@ -36,7 +36,7 @@ export const CACHE_EXPIRATION_KEY = new KeyDefinition<Date | null>(
* foreground instance to send out the notification. * foreground instance to send out the notification.
* TODO: Move to Auth Request service. * TODO: Move to Auth Request service.
*/ */
export const AUTH_REQUEST_PUSH_NOTIFICATION_KEY = new KeyDefinition<string>( export const AUTH_REQUEST_PUSH_NOTIFICATION_KEY = new KeyDefinition<string | null>(
LOGIN_STRATEGY_MEMORY, LOGIN_STRATEGY_MEMORY,
"authRequestPushNotification", "authRequestPushNotification",
{ {

View File

@@ -28,13 +28,18 @@ import {
} from "../models/request/update-devices-trust.request"; } from "../models/request/update-devices-trust.request";
/** Uses disk storage so that the device key can persist after log out and tab removal. */ /** Uses disk storage so that the device key can persist after log out and tab removal. */
export const DEVICE_KEY = new UserKeyDefinition<DeviceKey>(DEVICE_TRUST_DISK_LOCAL, "deviceKey", { export const DEVICE_KEY = new UserKeyDefinition<DeviceKey | null>(
deserializer: (deviceKey) => SymmetricCryptoKey.fromJSON(deviceKey) as DeviceKey, 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 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. */ /** Uses disk storage so that the shouldTrustDevice bool can persist across login. */
export const SHOULD_TRUST_DEVICE = new UserKeyDefinition<boolean>( export const SHOULD_TRUST_DEVICE = new UserKeyDefinition<boolean | null>(
DEVICE_TRUST_DISK_LOCAL, DEVICE_TRUST_DISK_LOCAL,
"shouldTrustDevice", "shouldTrustDevice",
{ {

View File

@@ -29,7 +29,7 @@ import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user
import { SetKeyConnectorKeyRequest } from "../models/request/set-key-connector-key.request"; import { SetKeyConnectorKeyRequest } from "../models/request/set-key-connector-key.request";
import { IdentityTokenResponse } from "../models/response/identity-token.response"; import { IdentityTokenResponse } from "../models/response/identity-token.response";
export const USES_KEY_CONNECTOR = new UserKeyDefinition<boolean>( export const USES_KEY_CONNECTOR = new UserKeyDefinition<boolean | null>(
KEY_CONNECTOR_DISK, KEY_CONNECTOR_DISK,
"usesKeyConnector", "usesKeyConnector",
{ {
@@ -38,7 +38,7 @@ export const USES_KEY_CONNECTOR = new UserKeyDefinition<boolean>(
}, },
); );
export const CONVERT_ACCOUNT_TO_KEY_CONNECTOR = new UserKeyDefinition<boolean>( export const CONVERT_ACCOUNT_TO_KEY_CONNECTOR = new UserKeyDefinition<boolean | null>(
KEY_CONNECTOR_DISK, KEY_CONNECTOR_DISK,
"convertAccountToKeyConnector", "convertAccountToKeyConnector",
{ {