From e1f9753d6d2dddc8d5b19b3f2e337edbda29c416 Mon Sep 17 00:00:00 2001 From: Michael Novotny Date: Thu, 23 Jul 2026 14:25:05 -0500 Subject: [PATCH] fix(orgs): enable organization creation defaults with --auto-create The API only auto-creates organizations when both organization_creation_defaults.enabled and the nested automatic_organization_creation.enabled are true. The --auto-create flag previously patched only the nested flag, so on instances where the umbrella setting was never enabled the command succeeded silently but no organization was ever auto-created. Co-Authored-By: Claude Fable 5 --- .changeset/orgs-auto-create-creation-defaults.md | 5 +++++ packages/cli-core/src/commands/orgs/README.md | 7 +++++++ packages/cli-core/src/commands/orgs/index.test.ts | 13 ++++++++----- packages/cli-core/src/commands/orgs/index.ts | 6 ++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 .changeset/orgs-auto-create-creation-defaults.md diff --git a/.changeset/orgs-auto-create-creation-defaults.md b/.changeset/orgs-auto-create-creation-defaults.md new file mode 100644 index 000000000..d21c4d2c7 --- /dev/null +++ b/.changeset/orgs-auto-create-creation-defaults.md @@ -0,0 +1,5 @@ +--- +"clerk": patch +--- + +Fix `clerk enable orgs --auto-create` so organizations are actually auto-created for new users. The flag now also enables organization creation defaults, which the API requires before honoring the automatic creation setting. diff --git a/packages/cli-core/src/commands/orgs/README.md b/packages/cli-core/src/commands/orgs/README.md index 8861e8c5a..f585f9c8d 100644 --- a/packages/cli-core/src/commands/orgs/README.md +++ b/packages/cli-core/src/commands/orgs/README.md @@ -29,6 +29,13 @@ clerk disable orgs [options] The boolean flags above are one-way: they set the field to `true` only. To clear a field, use `clerk config patch --json '{"organization_settings":{...}}'`. +`--auto-create` patches both `organization_creation_defaults.enabled` and +`organization_creation_defaults.automatic_organization_creation.enabled` — the +API only auto-creates organizations when both are true. When this enables +creation defaults for the first time, the API seeds the remaining sub-settings +(name template, fallback name, email-domain detection) with its standard +defaults. + ### `disable` | Flag | Description | diff --git a/packages/cli-core/src/commands/orgs/index.test.ts b/packages/cli-core/src/commands/orgs/index.test.ts index 8983ab18d..d03ab9997 100644 --- a/packages/cli-core/src/commands/orgs/index.test.ts +++ b/packages/cli-core/src/commands/orgs/index.test.ts @@ -150,7 +150,7 @@ describe("clerk enable/disable orgs", () => { expect(parsed.organization_settings.domains_enabled).toBe(true); }); - test("enable passes --auto-create flag", async () => { + test("enable --auto-create enables both organization_creation_defaults.enabled and the nested auto-creation flag", async () => { let capturedBody = ""; stubFetch(async (_input, init) => { if (init?.method === "PATCH") capturedBody = init.body as string; @@ -162,10 +162,13 @@ describe("clerk enable/disable orgs", () => { await orgsEnable({ autoCreate: true }); const parsed = JSON.parse(capturedBody); - expect( - parsed.organization_settings.organization_creation_defaults.automatic_organization_creation - .enabled, - ).toBe(true); + const defaults = parsed.organization_settings.organization_creation_defaults; + // FAPI only auto-creates organizations when BOTH the umbrella + // organization_creation_defaults.enabled and the nested flag are true — + // patching only the nested flag silently does nothing on instances where + // the umbrella was never enabled. + expect(defaults.enabled).toBe(true); + expect(defaults.automatic_organization_creation.enabled).toBe(true); }); test("enable --dry-run plumbs dry_run=true to the API and prints dry-run output", async () => { diff --git a/packages/cli-core/src/commands/orgs/index.ts b/packages/cli-core/src/commands/orgs/index.ts index d93ba7f06..aebf8076c 100644 --- a/packages/cli-core/src/commands/orgs/index.ts +++ b/packages/cli-core/src/commands/orgs/index.ts @@ -37,7 +37,13 @@ export async function orgsEnable(options: OrgsOptions): Promise { if (options.forceSelection) orgSettings.force_organization_selection = true; if (options.domains) orgSettings.domains_enabled = true; if (options.autoCreate) { + // The API only auto-creates organizations when BOTH the umbrella + // organization_creation_defaults.enabled and the nested flag are true. + // Sending both in one patch is safe: the backend's enable transition seeds + // defaults only for sub-settings not explicitly provided, and re-sending + // enabled=true on an already-enabled instance is a no-op. orgSettings.organization_creation_defaults = { + enabled: true, automatic_organization_creation: { enabled: true }, }; }