Skip to content

Commit 1f1c9d9

Browse files
committed
Validate when self-serve SSO is enabled
1 parent 317f492 commit 1f1c9d9

6 files changed

Lines changed: 24 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
disabledAllBillingFeatures,
1616
disabledOrganizationAPIKeysFeature,
1717
disabledOrganizationsFeature,
18+
disabledSelfServeSSOFeature,
1819
disabledUserAPIKeysFeature,
1920
isSignedInAndSingleSessionModeEnabled,
2021
noOrganizationExists,
@@ -72,9 +73,9 @@ import type {
7273
AuthenticateWithSolanaParams,
7374
BillingNamespace,
7475
CheckoutSignalValue,
76+
Clerk as ClerkInterface,
7577
ClerkAPIError,
7678
ClerkAuthenticateWithWeb3Params,
77-
Clerk as ClerkInterface,
7879
ClerkOptions,
7980
ClientJSONSnapshot,
8081
ClientResource,
@@ -209,6 +210,7 @@ const CANNOT_RENDER_SINGLE_SESSION_ENABLED_ERROR_CODE = 'cannot_render_single_se
209210
const CANNOT_RENDER_API_KEYS_DISABLED_ERROR_CODE = 'cannot_render_api_keys_disabled';
210211
const CANNOT_RENDER_API_KEYS_USER_DISABLED_ERROR_CODE = 'cannot_render_api_keys_user_disabled';
211212
const CANNOT_RENDER_API_KEYS_ORG_DISABLED_ERROR_CODE = 'cannot_render_api_keys_org_disabled';
213+
const CANNOT_RENDER_SELF_SERVE_SSO_DISABLED_ERROR_CODE = 'cannot_render_self_serve_sso_disabled';
212214
const defaultOptions: ClerkOptions = {
213215
polling: true,
214216
standardBrowser: true,
@@ -546,7 +548,7 @@ export class Clerk implements ClerkInterface {
546548
) {
547549
// Typing this.#options as ClerkOptions to ensure proper type checking. TypeScript will infer the type as `never`
548550
// since missing both `routerPush` and `routerReplace` is not a valid ClerkOptions.
549-
const options = this.#options;
551+
const options = this.#options as ClerkOptions;
550552
const missingRouter = !options.routerPush ? 'routerPush' : 'routerReplace';
551553
logger.warnOnce(
552554
`Clerk: Both \`routerPush\` and \`routerReplace\` need to be defined, but \`${missingRouter}\` is not defined. This may cause issues with navigation in your application.`,
@@ -1444,6 +1446,15 @@ export class Clerk implements ClerkInterface {
14441446
* @param props Configuration parameters.
14451447
*/
14461448
public __experimental_mountConfigureSSO = (node: HTMLDivElement, props?: __experimental_ConfigureSSOProps) => {
1449+
if (disabledSelfServeSSOFeature(this, this.environment)) {
1450+
if (this.#instanceType === 'development') {
1451+
throw new ClerkRuntimeError(warnings.cannotRenderConfigureSSOComponentWhenDisabled, {
1452+
code: CANNOT_RENDER_SELF_SERVE_SSO_DISABLED_ERROR_CODE,
1453+
});
1454+
}
1455+
return;
1456+
}
1457+
14471458
this.assertComponentsReady(this.#clerkUI);
14481459
const component = 'ConfigureSSO';
14491460
void this.#clerkUI
@@ -2993,8 +3004,8 @@ export class Clerk implements ClerkInterface {
29933004
this.#authService = await AuthCookieService.create(
29943005
this,
29953006
this.#fapiClient,
2996-
2997-
this.#instanceType,
3007+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3008+
this.#instanceType!,
29983009
this.#publicEventBus,
29993010
);
30003011

packages/clerk-js/src/core/resources/UserSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class UserSettings extends BaseResource implements UserSettingsResource {
105105
};
106106
enterpriseSSO: EnterpriseSSOSettings = {
107107
enabled: false,
108+
self_serve_sso: false,
108109
};
109110
passkeySettings: PasskeySettingsData = {
110111
allow_autofill: false,

packages/clerk-js/src/test/fixture-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ const createUserSettingsFixtureHelpers = (environment: EnvironmentJSON) => {
536536

537537
const withEnterpriseSso = () => {
538538
us.saml = { enabled: true };
539-
us.enterprise_sso = { enabled: true };
539+
us.enterprise_sso = { enabled: true, self_serve_sso: false };
540540
};
541541

542542
const withBackupCode = (opts?: Partial<UserSettingsJSON['attributes']['backup_code']>) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ export const disabledOrganizationAPIKeysFeature: ComponentGuard = (_, environmen
4545
export const disabledAllAPIKeysFeatures: ComponentGuard = (_, environment) => {
4646
return disabledUserAPIKeysFeature(_, environment) && disabledOrganizationAPIKeysFeature(_, environment);
4747
};
48+
49+
export const disabledSelfServeSSOFeature: ComponentGuard = (_, environment) => {
50+
return !environment?.userSettings.enterpriseSSO.self_serve_sso;
51+
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const warnings = {
6464
'The <APIKeys/> component cannot be rendered when organization API keys are disabled. Since organization API keys are disabled, this is no-op.',
6565
cannotRenderOAuthConsentComponentWhenUserDoesNotExist:
6666
'<OAuthConsent/> cannot render unless a user is signed in. Since no user is signed in, this is no-op.',
67+
cannotRenderConfigureSSOComponentWhenDisabled:
68+
'The <ConfigureSSO/> component cannot be rendered when self-serve SSO is disabled. Visit `https://dashboard.clerk.com` to enable the feature. Since self-serve SSO is disabled, this is no-op.',
6769
};
6870

6971
type SerializableWarnings = Serializable<typeof warnings>;

packages/shared/src/types/userSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type OAuthProviders = {
9292
};
9393
export type EnterpriseSSOSettings = {
9494
enabled: boolean;
95+
self_serve_sso: boolean;
9596
};
9697

9798
export type AttributesJSON = {

0 commit comments

Comments
 (0)