chore: migrate frontend auth from Clerk to Better Auth#4568
chore: migrate frontend auth from Clerk to Better Auth#4568NathanFlurry wants to merge 8 commits intomainfrom
Conversation
|
🚅 Deployed to the rivet-pr-4568 environment in rivet-frontend
|
573da5a to
6f69069
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR Review: Migrate Frontend Auth from Clerk to Better AuthOverviewThis PR replaces Clerk with Better Auth across the frontend. It removes ~2,500 lines of Clerk-specific code (ClerkProvider, Clerk Elements sign-in/sign-up flows, SSO callback routes, invitation acceptance, waitForClerk utility) and replaces them with Better Auth's createAuthClient plus cookie-based sessions. The overall direction is correct and the diff is clean, but there are several issues worth addressing before merging. IssuesE2E test auth flow is likely broken (e2e/auth.setup.ts) The setup now calls request.post to sign in via the Better Auth API, then navigates to /. Playwright's request fixture uses a separate network context from page - cookies set via request.post are not automatically shared with the browser page. The session cookie won't be present when page.goto("/") runs, so the auth state will never be saved. The test should sign in through the browser UI (fill the form on /login) or use Playwright's APIRequestContext attached to the browser context. Hardcoded base URL in E2E test const baseURL = "http://localhost:43710" is hardcoded in auth.setup.ts. This will fail in any environment that doesn't use that exact port. Should use process.env.BASE_URL or the Playwright config's base URL. Sentry/PostHog user identification silently removed waitForClerk.ts included Sentry.setUser and posthog.setPersonProperties calls. Deleting it without a replacement means user identification for error tracking and analytics is gone. This is an observability regression. Unconditional setActive on every org navigation (routes/_context/_cloud/orgs.$organization.tsx) The old code only called clerk.setActive when the org ID changed. The new code calls authClient.organization.setActive unconditionally on every navigation to an org route. This makes a network request on every route load and could cause unnecessary session updates or flicker. Duplicated slug generation logic Slug generation with a random suffix appears in both create-organization-frame.tsx and choose-organization.tsx. Extract it to a shared utility (e.g. lib/slug.ts). Redundant inner try/catch in login handler (src/app/login.tsx) The inner try/catch in handleSubmit that immediately re-throws adds no value; remove it and let the outer catch handle redirect errors. Profile/Settings/Members menu items removed without replacement (user-dropdown.tsx) The user profile, org settings, and org members DropdownMenuItems that called Clerk's openUserProfile / openOrganizationProfile were removed. If these features are intended to still exist (e.g. via a dedicated settings route), they need to be wired up; otherwise this is a user-visible regression. Missing email verification flow Clerk handled email verification as part of sign-up. It's not clear whether Better Auth's email verification is configured or whether new sign-ups are automatically considered verified. If email verification is required, the sign-up success path should handle the unverified state. Observations (non-blocking)
SummaryThe migration is well-scoped and removes a large external dependency cleanly. The main blocker is the E2E test setup (cookies won't transfer between Playwright's request context and page context), and the missing Sentry/PostHog identification is a silent observability regression. The other items above are worth fixing before shipping. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ropdown Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ences Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6f69069 to
097cc72
Compare
Preview packages published to npmInstall with: npm install rivetkit@pr-4568All packages published as Engine binary is shipped via Docker images: docker pull rivetdev/engine:slim-54ca6fd
docker pull rivetdev/engine:full-54ca6fdIndividual packagesnpm install rivetkit@pr-4568
npm install @rivetkit/react@pr-4568
npm install @rivetkit/rivetkit-native@pr-4568
npm install @rivetkit/sqlite-wasm@pr-4568
npm install @rivetkit/workflow-engine@pr-4568 |

Summary
Test plan
🤖 Generated with Claude Code