fix(platform): auto-create default org only on truly fresh instances#1702
Conversation
Commit 9b92396 replaced the dashboard's auto-create-default flow with an unconditional redirect to the create-organization form. That broke the invariant relied on by many hardcoded `orgSlug: 'default'` callsites (agents, chat, integrations, providers, login policy, etc.): on a fresh instance, the first user picked a free-form name, ended up with a non-`default` slug, and every hardcoded reference misfired. Restore the auto-create, but only when the instance has zero organizations. Add an auth-gated `instanceHasAnyOrganization` query (mirrors the existing `hasAnyUsers` helper pattern), and gate the dashboard's 0-membership branch on it: - instance has 0 orgs -> seed `default`, set active, init workflows, record switch, navigate to /dashboard/$id - instance has >=1 org, user has 0 -> redirect to create-organization form (current 9b92396 behavior; multi-org deployments, uninvited users) - user has >=1 membership -> unchanged (last-active routing) On auto-create failure (e.g. slug-conflict race against another tab), invalidate the cached existence query and drop the resolved guard so the effect re-runs and routes the loser through the form branch.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds automatic seeding of a default organization for users logging in to empty instances. It introduces a backend Convex query ( Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Commit 9b92396 replaced the dashboard's auto-create-
default-org flow with an unconditional redirect to the create-organization form. That broke the invariant relied on by many hardcodedorgSlug: 'default'callsites (agents, chat, integrations, providers, login policy, etc.): on a fresh instance, the first user picked a free-form name, ended up with a non-defaultslug, and every hardcoded reference misfired. This PR restores the auto-create, but only when the instance has zero organizations; multi-org deployments and uninvited users still get the form.Branching
default, set active, init workflows, record switch, navigate to/dashboard/$id/dashboard/create-organization(current 9b92396 behavior)Implementation
instanceHasAnyOrganizationquery (auth-gated, mirrors the existinghasAnyUsershelper pattern; one-rowfindManyfor fast existence check).instanceHasAnyOrg. On auto-create failure (e.g. slug-conflict race against another tab/user), the cached existence query is invalidated andresolvedRefis reset so the effect re-runs and routes the loser through the form branch — no orphan state.Known follow-up (out of scope)
In scenario B, if the user types "Default" / "default" into the form, the server-side
beforeCreateOrganizationalready rejects withOrganization slug "default" is already taken., but the form's generic error toast obscures it. Surfacing the server message verbatim is a separate UX polish.Pre-merge checklist
bun run check(format, lint, typecheck, all tests) — all 38 tasks succeeded, 3377 tests passed, 0 lint errors.services/platform/messages/{en,de,fr}.jsonfor any new/renamed/removed keys — N/A (no user-facing strings changed).docs/,docs/de/, anddocs/fr/for every user-visible change — N/A (internal redirect-branch logic; the user-facing form and dashboard surfaces are unchanged).bun run --filter @tale/docs lint(broken links + oxlint) — N/A (no docs touched).README.md,README.de.md,README.fr.mdif the change affects what they document — N/A.Test plan
/dashboard/<orgId>withslug=default. Open a feature that hardcodes'default'(e.g. integrations or chat) and confirm it works.defaultalready present, sign up a brand-new user → redirected to/dashboard/create-organization. Submit name "Acme" →acmeorg created, lands on its dashboard. Try name "Default" → friendly server error toast./dashboard/create-organizationwith no orphan state.Summary by CodeRabbit
Release Notes