Skip to content

feat(auth): migrate authentication to Better Auth - #340

Merged
pawelgalazka merged 18 commits into
mainfrom
feat/migrate-to-better-auth
Aug 6, 2026
Merged

feat(auth): migrate authentication to Better Auth#340
pawelgalazka merged 18 commits into
mainfrom
feat/migrate-to-better-auth

Conversation

@pawelgalazka

Copy link
Copy Markdown
Contributor

Summary

  • Replace the previous auth stack with Better Auth (email OTP, sessions, access-control roles)
  • Move Polar checkout/webhooks onto Better Auth Polar plugins and drop the custom permissions module
  • Add auth role helpers/tests, dynamic allowedHosts, and related login/checkout fixes

Test plan

  • Log in with email OTP and confirm session persists across reload
  • Log out and confirm protected routes redirect to login
  • Verify role-based guards (user / admin / premium / elite) still enforce correctly
  • Run Polar checkout (success + missing-config dialog) and confirm webhook/role updates
  • Run bun run check and bun run test

Made with Cursor

pawelgalazka and others added 14 commits July 27, 2026 18:49
Replace custom email OTP sessions with Better Auth, wire Turnstile and Polar plugins, and move access control into apps/auth.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep useFormAction and hidden email state for the OTP step while calling Better Auth from the server action.

Co-authored-by: Cursor <cursoragent@cursor.com>
Align with TanStack Start client-only convention and lazy-load it from CheckoutButton to avoid SSR import protection warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep Polar opt-in, return a clear error when POLAR_ACCESS_TOKEN is unset, and show it via ui-lite Dialog.

Co-authored-by: Cursor <cursoragent@cursor.com>
Turnstile is already enforced in the login form action, so the HTTP captcha plugin is redundant.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Align the client module export name and update checkout callers/docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep auth config focused on core auth and own Polar plugin wiring in payments.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Preview and test builds set PROD=true, so product IDs and Polar server
must key off CLOUDFLARE_ENV via vite --mode / getAppMode().

Co-authored-by: Cursor <cursoragent@cursor.com>
Ensures vite --mode (and getAppMode) resolve to preview instead of
defaulting to production when running bun run preview.

Co-authored-by: Cursor <cursoragent@cursor.com>
Payments still maps any non-production mode to preview product IDs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pawelgalazka
pawelgalazka merged commit 00dbd63 into main Aug 6, 2026
6 checks passed
@pawelgalazka
pawelgalazka deleted the feat/migrate-to-better-auth branch August 6, 2026 08:01
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.

1 participant