Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/mosaic-passkeys-shared-enterprise-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AttributeData, UserResource, VerificationResource } from '@clerk/shared/types';
import type { AttributeData, VerificationResource } from '@clerk/shared/types';

import { isAttributeAvailable } from './user-profile.utils';
import type { UserProfileContact } from './user-profile-contact.types';
Expand All @@ -20,15 +20,6 @@ export function toContactAccess(
return { show: available && (canCreate || count > 0), canCreate, canRemove: mutable };
}

export function canAddIdentifications(user: UserResource, enterpriseSSOEnabled: boolean): boolean {
return (
!enterpriseSSOEnabled ||
!user.enterpriseAccounts.some(
account => account.active && account.enterpriseConnection?.disableAdditionalIdentifications,
)
);
}

export function byId<T extends { id: string }>(items: T[], id: string, kind: string): T {
const item = items.find(item => item.id === id);
if (!item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type { EmailAddressResource, UserResource } from '@clerk/shared/types';

import type { MosaicRouter } from '../../../hooks/use-mosaic-router';
import { useMosaicRouter } from '../../../hooks/use-mosaic-router';
import { allowsIdentificationCreation } from '../../../utils/allows-identification-creation';
import { save } from '../../../utils/errors';
import { useReverificationFlow } from '../../reverification';
import type { UserProfileEmailVerification, UserProfileEmailVerifier } from '../user-profile-contact.types';
import { byId, canAddIdentifications, toContactAccess, toContacts } from '../user-profile-contact.utils';
import { byId, toContactAccess, toContacts } from '../user-profile-contact.utils';
import { useUserProfileUserModel } from '../user-profile-user.model';
import type { UserProfileAddEmailField } from './user-profile-add-email.controller';
import type { UserProfileEmailSectionModel } from './user-profile-email-section.types';
Expand Down Expand Up @@ -104,7 +105,7 @@ export function useUserProfileEmailSectionModel(): UserProfileEmailSectionModel
const access = toContactAccess(
attributes.email_address,
user.emailAddresses.length,
canAddIdentifications(user, enterpriseSSO.enabled),
allowsIdentificationCreation(user, enterpriseSSO),
);

if (!access.show) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FormSubmitError } from '../../../components/form';
import { getMosaicEnvironment, useMosaicEnvironment } from '../../../hooks/use-mosaic-environment';
import { useNow } from '../../../hooks/use-now';
import { fill, useLocale, useMessages } from '../../../localization';
import { allowsIdentificationCreation } from '../../../utils/allows-identification-creation';
import { save, SaveError } from '../../../utils/errors';
import type { ReverificationController } from '../../reverification';
import { useReverificationFlow } from '../../reverification';
Expand Down Expand Up @@ -76,11 +77,7 @@ function getPasskeysProjection(
return projectPasskeys({
passkeys: user.passkeys,
enabled: Boolean(environment.userSettings.attributes.passkey?.enabled),
allowIdentificationCreation:
!environment.userSettings.enterpriseSSO.enabled ||
!user.enterpriseAccounts.some(
account => account.active && account.enterpriseConnection?.disableAdditionalIdentifications,
),
allowIdentificationCreation: allowsIdentificationCreation(user, environment.userSettings.enterpriseSSO),
isSatellite,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useClerk } from '@clerk/shared/react';
import type { PhoneNumberResource, UserResource } from '@clerk/shared/types';

import { toCountryIso } from '../../../components/phone-input';
import { allowsIdentificationCreation } from '../../../utils/allows-identification-creation';
import { save } from '../../../utils/errors';
import { useReverificationFlow } from '../../reverification';
import type { UserProfilePhoneVerifier } from '../user-profile-contact.types';
import { byId, canAddIdentifications, toContactAccess, toContacts } from '../user-profile-contact.utils';
import { byId, toContactAccess, toContacts } from '../user-profile-contact.utils';
import { useUserProfileUserModel } from '../user-profile-user.model';
import type { UserProfileAddPhoneField } from './user-profile-add-phone.controller';
import type { UserProfilePhoneSectionModel } from './user-profile-phone-section.types';
Expand Down Expand Up @@ -40,7 +41,7 @@ export function useUserProfilePhoneSectionModel(): UserProfilePhoneSectionModel
const access = toContactAccess(
attributes.phone_number,
user.phoneNumbers.length,
canAddIdentifications(user, enterpriseSSO.enabled),
allowsIdentificationCreation(user, enterpriseSSO),
);

if (!access.show) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ describe('allowsIdentificationCreation', () => {
expect(allowsIdentificationCreation(blocked, enterpriseSSO)).toBe(false);
});

it('allows creation when the enterprise connection is inactive or enterprise SSO is off', () => {
it('allows creation when the enterprise connection permits it, is inactive, or enterprise SSO is off', () => {
const permitted = {
enterpriseAccounts: [{ active: true, enterpriseConnection: { disableAdditionalIdentifications: false } }],
};
expect(allowsIdentificationCreation(permitted, enterpriseSSO)).toBe(true);

const inactive = {
enterpriseAccounts: [{ active: false, enterpriseConnection: { disableAdditionalIdentifications: true } }],
};
Expand Down
Loading