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
5 changes: 5 additions & 0 deletions .changeset/orgs-auto-create-creation-defaults.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions packages/cli-core/src/commands/orgs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
13 changes: 8 additions & 5 deletions packages/cli-core/src/commands/orgs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/cli-core/src/commands/orgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export async function orgsEnable(options: OrgsOptions): Promise<void> {
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 },
};
}
Expand Down