Skip to content

Commit 4d5027b

Browse files
authored
chore(ui): Guard ConfigureSSO based on active organization (#8613)
1 parent 79cdd1f commit 4d5027b

5 files changed

Lines changed: 45 additions & 15 deletions

File tree

‎.changeset/tangy-jeans-crash.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/shared': patch
4+
---
5+
6+
Guard `ConfigureSSO` based on active organization

‎packages/clerk-js/src/core/clerk.ts‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ export class Clerk implements ClerkInterface {
960960

961961
if (noOrganizationExists(this)) {
962962
if (this.#instanceType === 'development') {
963-
throw new ClerkRuntimeError(warnings.cannotRenderComponentWhenOrgDoesNotExist, {
963+
throw new ClerkRuntimeError(warnings.createCannotRenderComponentWhenOrgDoesNotExist('OrganizationProfile'), {
964964
code: CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE,
965965
});
966966
}
@@ -1131,7 +1131,7 @@ export class Clerk implements ClerkInterface {
11311131
const userExists = !noUserExists(this);
11321132
if (noOrganizationExists(this) && userExists) {
11331133
if (this.#instanceType === 'development') {
1134-
throw new ClerkRuntimeError(warnings.cannotRenderComponentWhenOrgDoesNotExist, {
1134+
throw new ClerkRuntimeError(warnings.createCannotRenderComponentWhenOrgDoesNotExist('OrganizationProfile'), {
11351135
code: CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE,
11361136
});
11371137
}
@@ -1462,28 +1462,43 @@ export class Clerk implements ClerkInterface {
14621462
* @param props Configuration parameters.
14631463
*/
14641464
public mountConfigureSSO = (node: HTMLDivElement, props?: ConfigureSSOProps) => {
1465-
if (disabledSelfServeSSOFeature(this, this.environment)) {
1465+
const { isEnabled: isOrganizationsEnabled } = this.__internal_attemptToEnableEnvironmentSetting({
1466+
for: 'organizations',
1467+
caller: 'ConfigureSSO',
1468+
onClose: () => {
1469+
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('ConfigureSSO'), {
1470+
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
1471+
});
1472+
},
1473+
});
1474+
1475+
if (!isOrganizationsEnabled) {
1476+
return;
1477+
}
1478+
1479+
const userExists = !noUserExists(this);
1480+
if (noOrganizationExists(this) && userExists) {
14661481
if (this.#instanceType === 'development') {
1467-
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenDisabled, {
1468-
code: CANNOT_RENDER_SELF_SERVE_SSO_DISABLED_ERROR_CODE,
1482+
throw new ClerkRuntimeError(warnings.createCannotRenderComponentWhenOrgDoesNotExist('ConfigureSSO'), {
1483+
code: CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE,
14691484
});
14701485
}
14711486
return;
14721487
}
14731488

1474-
if (disabledEmailAddressAttribute(this, this.environment)) {
1489+
if (disabledSelfServeSSOFeature(this, this.environment)) {
14751490
if (this.#instanceType === 'development') {
1476-
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenEmailAddressDisabled, {
1477-
code: CANNOT_RENDER_CONFIGURE_SSO_EMAIL_ADDRESS_DISABLED_ERROR_CODE,
1491+
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenDisabled, {
1492+
code: CANNOT_RENDER_SELF_SERVE_SSO_DISABLED_ERROR_CODE,
14781493
});
14791494
}
14801495
return;
14811496
}
14821497

1483-
if (noUserExists(this)) {
1498+
if (disabledEmailAddressAttribute(this, this.environment)) {
14841499
if (this.#instanceType === 'development') {
1485-
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenUserDoesNotExist, {
1486-
code: CANNOT_RENDER_USER_MISSING_ERROR_CODE,
1500+
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenEmailAddressDisabled, {
1501+
code: CANNOT_RENDER_CONFIGURE_SSO_EMAIL_ADDRESS_DISABLED_ERROR_CODE,
14871502
});
14881503
}
14891504
return;

‎packages/shared/src/internal/clerk-js/componentGuards.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export const disabledAllAPIKeysFeatures: ComponentGuard = (_, environment) => {
4646
return disabledUserAPIKeysFeature(_, environment) && disabledOrganizationAPIKeysFeature(_, environment);
4747
};
4848

49-
export const disabledSelfServeSSOFeature: ComponentGuard = (_, environment) => {
50-
return !environment?.userSettings.enterpriseSSO.self_serve_sso;
49+
export const disabledSelfServeSSOFeature: ComponentGuard = (clerk, environment) => {
50+
return !environment?.userSettings.enterpriseSSO.self_serve_sso || !clerk.organization?.selfServeSSOEnabled;
5151
};
5252

5353
export const disabledEmailAddressAttribute: ComponentGuard = (_, environment) => {

‎packages/shared/src/internal/clerk-js/warnings.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ const createMessageForDisabledOrganizations = (
1010
| 'OrganizationSwitcher'
1111
| 'OrganizationList'
1212
| 'CreateOrganization'
13-
| 'TaskChooseOrganization',
13+
| 'TaskChooseOrganization'
14+
| 'ConfigureSSO',
1415
) => {
1516
return formatWarning(
1617
`The <${componentName}/> cannot be rendered when the feature is turned off. Visit 'dashboard.clerk.com' to enable the feature. Since the feature is turned off, this is no-op.`,
1718
);
1819
};
20+
21+
const createCannotRenderComponentWhenOrgDoesNotExist = (componentName: 'OrganizationProfile' | 'ConfigureSSO') => {
22+
return formatWarning(
23+
`<${componentName}/> cannot render unless an organization is active. Since no organization is currently active, this is no-op.`,
24+
);
25+
};
26+
1927
const createMessageForDisabledBilling = (componentName: 'PricingTable' | 'Checkout' | 'PlanDetails') => {
2028
return formatWarning(
2129
`The <${componentName}/> component cannot be rendered when billing is disabled. Visit 'https://dashboard.clerk.com/last-active?path=billing/settings' to follow the necessary steps to enable billing. Since billing is disabled, this is no-op.`,
@@ -45,7 +53,7 @@ const warnings = {
4553
'The <SignIn/> component cannot render when a user has a pending task, unless the application allows multiple sessions. Since a user is signed in and this application only allows a single session, Clerk is redirecting to the task instead.',
4654
cannotRenderComponentWhenUserDoesNotExist:
4755
'<UserProfile/> cannot render unless a user is signed in. Since no user is signed in, this is no-op.',
48-
cannotRenderComponentWhenOrgDoesNotExist: `<OrganizationProfile/> cannot render unless an organization is active. Since no organization is currently active, this is no-op.`,
56+
createCannotRenderComponentWhenOrgDoesNotExist,
4957
cannotRenderAnyOrganizationComponent: createMessageForDisabledOrganizations,
5058
cannotRenderAnyBillingComponent: createMessageForDisabledBilling,
5159
cannotOpenUserProfile:

‎packages/shared/src/types/clerk.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ export type __internal_AttemptToEnableEnvironmentSettingParams = {
16441644
| 'OrganizationList'
16451645
| 'CreateOrganization'
16461646
| 'TaskChooseOrganization'
1647+
| 'ConfigureSSO'
16471648
| 'useOrganizationList'
16481649
| 'useOrganization';
16491650
onClose?: () => void;

0 commit comments

Comments
 (0)