Skip to content

Port from Supabase to Neon + Better Auth#5

Merged
f1shyfang merged 1 commit into
mainfrom
port/supabase-to-neon-betterauth
May 30, 2026
Merged

Port from Supabase to Neon + Better Auth#5
f1shyfang merged 1 commit into
mainfrom
port/supabase-to-neon-betterauth

Conversation

@f1shyfang
Copy link
Copy Markdown
Owner

Summary

Moves the database to Neon (plain Postgres, accessed via a server-side pg pool) and replaces Supabase Auth with Better Auth (cookie sessions). All Supabase dependencies are removed. Per the decision during planning, this is a clean slate — no data/user migration.

Database → Neon

  • server/db.js points at DATABASE_URL with SSL; it's the single data-access path.
  • Migrations moved supabase/db/migrations/; user-id columns switched uuidtext to match Better Auth ids.
  • RLS migration dropped (auth.uid() is Supabase-only and adds nothing to a server-only pool). The market_resolve_with_ledger RPC ports unchanged.
  • Every Supabase SDK call (.from().select().eq(), .rpc()) and the PostgREST waitlist fetch rewritten to parameterized SQL across API routes, resolveHandler.js, and idempotency.js.

Auth → Better Auth

  • New: lib/auth.js (server instance + getUserFromRequest), lib/authClient.js (browser), pages/api/auth/[...all].js.
  • A user.create hook mirrors each auth user into the domain users table (users.id == user.id, display_name from signup, 2000 starting points).
  • Frontend Bearer-token plumbing removed across 7 files — same-origin cookies carry the session.
  • Deleted server/supabase*.js and lib/supabase.js.

Verification

  • npm run build
  • npm run test:db ✅ and npm test ✅ — 12/12 integration assertions against Neon (resolve flow, ledger payouts, idempotency, auth guard).
  • Live dev-server 14/14 end-to-end: signup → session → group → market → invite → 2nd-user join → predictions → 401 guard → resolve → leaderboard (balance 2100). Confirmed users.id == "user".id with passwords stored.

Deploy notes

Set DATABASE_URL, BETTER_AUTH_SECRET, and BETTER_AUTH_URL (prod URL) as environment variables. Neon schema is already migrated.

🤖 Generated with Claude Code

Move the database to Neon (plain Postgres, server-side pg pool) and replace
Supabase Auth with Better Auth (cookie sessions). Removes all Supabase deps.

Database:
- server/db.js points at DATABASE_URL with SSL; single data-access path
- migrations moved supabase/ -> db/migrations/; user-id columns uuid -> text
  to match Better Auth ids; RLS migration dropped (auth.uid() is Supabase-only)
- all Supabase SDK queries (.from/.rpc) and the PostgREST waitlist fetch
  rewritten to parameterized SQL across API routes, resolveHandler, idempotency

Auth:
- lib/auth.js (server instance + getUserFromRequest), lib/authClient.js (browser),
  pages/api/auth/[...all].js handler
- user.create hook mirrors each auth user into the domain users table
  (users.id == user.id, display_name from signup, 2000 starting points)
- frontend Bearer-token plumbing removed; same-origin cookies carry the session
- deleted server/supabase*.js and lib/supabase.js

Tests rewritten to run against Neon via pg.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 30, 2026 04:56
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
betcha Ready Ready Preview, Comment May 30, 2026 4:56am

@f1shyfang f1shyfang merged commit 0212773 into main May 30, 2026
2 of 3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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