Skip to content

fix: org creation#897

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-02-fix_org_creation
May 3, 2026
Merged

fix: org creation#897
graphite-app[bot] merged 1 commit intomainfrom
05-02-fix_org_creation

Conversation

@MaheshtheDev
Copy link
Copy Markdown
Member

No description provided.

@MaheshtheDev MaheshtheDev marked this pull request as ready for review May 3, 2026 00:21
@graphite-app graphite-app Bot requested a review from Dhravya May 3, 2026 00:21
Copy link
Copy Markdown
Member Author


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented May 3, 2026

Claude finished @MaheshtheDev's task in 58s —— View job


Review Complete

  • Fetching PR diff
  • Analyzing changes for bugs, security issues, and logic errors
  • Submitting review

Summary: This is a clean bug fix that correctly accesses the organization slug from the Better Auth response structure (result.data?.slug instead of directly accessing .slug on the result object). No issues found — good to ship.

Score: 10/10

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 3, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 703ebf7 May 03 2026, 12:24 AM

@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented May 3, 2026

Merge activity

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Fixes org creation by correctly accessing the slug from the Better Auth response structure (result.data?.slug instead of newOrg.slug).

Issues found: None — this looks good to ship.

The fix correctly handles the Better Auth API response format which wraps the organization data in a data property. The fallback to the locally generated slug provides resilience if the API response is incomplete. The change from ?? to || for the name is also appropriate to handle empty string edge cases.

Score: 10/10

@graphite-app graphite-app Bot force-pushed the 05-02-fix_org_creation branch from 5459a88 to 703ebf7 Compare May 3, 2026 00:23
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 3, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 703ebf7 Commit Preview URL May 03 2026, 12:26 AM

@graphite-app graphite-app Bot merged commit 703ebf7 into main May 3, 2026
6 of 8 checks passed
Copy link
Copy Markdown
Contributor

@vorflux vorflux Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed -- found 1 issue related to missing error handling on the org creation result.


Review with Vorflux

Comment on lines +449 to +454
const result = await authClient.organization.create({
name,
slug: generateOrgSlug(name),
slug,
metadata: { signupSource: "consumer" },
})
await setActiveOrg(newOrg.slug)
await setActiveOrg(result.data?.slug ?? slug)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] organization.create errors silently fall back to a potentially invalid slug.

Since authClient is configured without fetchOptions.throw, Better Auth client calls resolve as { data, error } on HTTP errors rather than throwing. With result.data?.slug ?? slug, any create failure (auth/session issues, org limits, slug conflict) falls back to the locally generated slug and calls setActiveOrg with a slug that may not exist on the server. Onboarding then continues as if setup succeeded.

Suggested fix -- check the result before activating:

const result = await authClient.organization.create({
  name,
  slug,
  metadata: { signupSource: "consumer" },
})
if (result.error || !result.data?.slug) {
  throw new Error(result.error?.message ?? "Failed to create organization")
}
await setActiveOrg(result.data.slug)

This avoids proceeding with a non-existent org.

@vorflux
Copy link
Copy Markdown
Contributor

vorflux Bot commented May 3, 2026

Testing Results

The fix was verified at three independent levels:

1. TypeScript Type-Check

  • bunx tsc --noEmit confirms zero slug-related errors in the PR file
  • The old onboarding file (app/(app)/old/onboarding/welcome/page.tsx line 155) raises TS2339: Property 'slug' does not exist on type 'Data<{...}> | Error$1<...>' -- independently proving the old pattern was always invalid

2. Logic Simulation

  • Old code bug confirmed: newOrg.slug is always undefined because organization.create() returns { data, error }, not the org directly. setActiveOrg(undefined) silently early-returns, leaving the org unactivated.
  • New code verified: result.data?.slug correctly unwraps the response. The ?? slug fallback provides resilience.
  • || vs ?? for name: When user.name = "" (common from OAuth providers), ?? passes the empty string through (org named ""), while || correctly falls back to email.

3. End-to-End Live Test

Authenticated as a user with empty-string name and 0 organizations -- the exact edge case this PR fixes.

Step Result
Onboarding page loaded Rendered correctly
X handle entered, submitted ensureOrg ran, flow advanced
Skipped to dashboard Workspace active in nav

API verification: 1 org created, named from email fallback (supermemory@agentmail.to), slug supermemory-agentmail-to-433394, metadata signupSource: consumer. Org was both created AND activated correctly.

Screenshots:

Recording:


Follow-up: Same bug exists in old onboarding path

apps/web/app/(app)/old/onboarding/welcome/page.tsx line 155 has the identical newOrg.slug bug. TypeScript raises the same error there. Consider applying the same fix if that path is still reachable.


Attached Images and Videos

prod-onboarding-authed.png

onboarding-x-handle-entered.png

onboarding-after-submit.png

onboarding-complete-dashboard.png

🎥 View recording: onboarding-authenticated-pr-897.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants