brackt/drizzle
Chris Parsons ba9bf64e37
Migrate authentication from Clerk to BetterAuth (#324)
* Migrate authentication from Clerk to BetterAuth (#322)

Replaces @clerk/react-router with self-hosted better-auth to eliminate
the external Clerk dependency and keep all user/session data in our own
PostgreSQL database.

**What changed**
- New: auth.server.ts (BetterAuth config w/ Drizzle adapter, bcrypt, Resend), auth-client.ts, api.auth.$.ts handler
- New: /login and /register pages with email+password and Google/Discord OAuth; open-redirect guard on redirectTo param
- New: UserMenu component replacing Clerk's UserButton
- Schema: sessions, accounts, verifications tables; emailVerified column; clerkId made nullable
- Migrations 0081 (BetterAuth tables) and 0082 (accounts extra columns for v1.6.9)
- All ~30 route files: getAuth → auth.api.getSession, isUserAdminByClerkId → isUserAdmin
- root.tsx: isAdmin read directly from session.user.isAdmin (no extra DB query)
- useDraftAuthRecovery: removed Clerk JWT refresh logic; replaced with cookie-session check
- models/user.ts: removed findUserByClerkId, findOrCreateUser, updateUserByClerkId (webhook pattern)
- Deleted: app/routes/api/webhooks/clerk.ts; uninstalled @clerk/react-router, @clerk/themes, svix
- scripts/migrate.mjs: extended with idempotent Clerk → BetterAuth data migration (FK conversion, email_verified, OAuth accounts)
- scripts/migrate-clerk-passwords.mjs: one-time script to import bcrypt hashes from Clerk CSV export
- BETTERAUTH_MIGRATION.md: dev and production runbooks
- All test mocks updated: vi.mock('~/lib/auth.server') instead of @clerk/react-router/server
- Test fixtures: added emailVerified field

**Follow-up (post-stable)**
- Rename actor_clerk_id column → actor_user_id in commissioner_audit_log
- Drop clerk_id column from users once migration confirmed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add .npmrc with legacy-peer-deps for better-auth/drizzle peer dep conflict

better-auth@1.6.9 declares peerOptional deps on drizzle-orm ^0.45.2 and
drizzle-kit >=0.31.4, but we run drizzle-orm ~0.36.3 / drizzle-kit ~0.28.1.
The adapter works correctly at runtime with our versions — the peer dep is
only for stricter type checking. This unblocks npm ci in CI without a risky
drizzle major-version upgrade.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 22:00:49 -07:00
..
meta Migrate authentication from Clerk to BetterAuth (#324) 2026-04-24 22:00:49 -07:00
0000_short_donald_blake.sql
0001_serious_la_nuit.sql
0002_tired_iron_man.sql
0003_public_shadowcat.sql
0004_spicy_zarda.sql
0005_abnormal_thunderbird.sql
0006_needy_junta.sql
0007_pink_nebula.sql
0008_salty_trauma.sql
0009_fuzzy_korvac.sql
0010_complex_the_stranger.sql
0011_gifted_mystique.sql
0012_yielding_phil_sheldon.sql
0013_pink_the_order.sql
0014_lowly_gateway.sql
0015_exotic_loners.sql
0016_majestic_roulette.sql
0017_calm_zarda.sql
0018_numerous_stardust.sql feat: add public draft board and simplify draft speed settings 2025-10-20 15:03:11 -07:00
0019_acoustic_ben_grimm.sql feat: add autodraft status and team connection indicators to draft grid 2025-10-21 23:22:17 -07:00
0020_slim_spacker_dave.sql feat: Add comprehensive scoring system database schema 2025-10-28 23:40:11 -07:00
0021_fair_ser_duncan.sql feat: Implement bracket expansion plan to support various tournament structures 2025-11-03 09:36:16 -08:00
0022_shiny_mother_askani.sql feat: Implement bracket expansion plan to support various tournament structures 2025-11-03 09:36:16 -08:00
0023_cynical_jack_power.sql Refactor code structure for improved readability and maintainability 2025-11-03 13:16:37 -08:00
0024_faithful_mesmero.sql feat: implement Expected Value System with ICM probability calculator 2025-11-17 22:19:46 -08:00
0025_rename_participant_ev_season_to_sports_season.sql feat: implement Expected Value System with ICM probability calculator 2025-11-17 22:19:46 -08:00
0026_add_source_odds_to_participant_ev.sql feat: implement Expected Value System with ICM probability calculator 2025-11-17 22:19:46 -08:00
0027_add_projected_points_to_team_standings.sql feat: add FIFA World Cup 48-team bracket template with group stage and projected scoring 2026-02-14 22:30:12 -08:00
0028_add_tournament_groups.sql feat: add FIFA World Cup 48-team bracket template with group stage and projected scoring 2026-02-14 22:30:12 -08:00
0029_change_participant_ev_to_decimal.sql Change participant expectedValue from integer to decimal (#1) 2026-02-19 11:26:40 -08:00
0030_add_draft_picks_unique_slot.sql fix: harden draft timer system with race-condition safety and DRY refactor (#34) 2026-02-23 23:23:24 -08:00
0031_add_autodraft_queue_only.sql Claude/redesign autodraft queue c4 kp r (#40) 2026-02-27 22:16:26 -08:00
0032_consolidate_playoff_pattern.sql User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
0033_add_schedule_event_type.sql fix: add statement-breakpoint to schedule_event enum migration (#86) 2026-03-07 22:45:59 -08:00
0034_add_ev_snapshots.sql User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
0035_increase_prob_precision.sql User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
0036_increase_ev_precision.sql User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
0037_add_simulator_type_to_sports.sql User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
0038_sad_wilson_fisk.sql feat: progressive floor scoring for playoff brackets (#100) 2026-03-10 10:27:58 -07:00
0039_add_ucl_bracket_simulator_type.sql Fix bad migration. 2026-03-11 14:38:45 -07:00
0040_fat_puma.sql Found it in a second spot. 2026-03-11 14:47:19 -07:00
0041_great_magma.sql Add event_starts_at timestamp to scoring events for sub-day ordering (#146) 2026-03-15 10:22:42 -07:00
0042_migrate_event_date_to_starts_at.sql Add event_starts_at timestamp to scoring events for sub-day ordering (#146) 2026-03-15 10:22:42 -07:00
0043_demonic_vanisher.sql Add per-event configurable region config for NCAA-style brackets (#149) (#149) 2026-03-15 21:52:47 -07:00
0044_add_ncaam_bracket_simulator_type.sql Add NCAAM and NCAAW bracket Monte Carlo simulators (#150) 2026-03-15 23:31:47 -07:00
0045_add_ncaaw_bracket_simulator_type.sql Add NCAAM and NCAAW bracket Monte Carlo simulators (#150) 2026-03-15 23:31:47 -07:00
0046_add_nba_bracket_simulator_type.sql Add NBA playoff bracket Monte Carlo simulator (#154) 2026-03-16 21:43:39 -07:00
0047_fix_nba_bracket_simulator_type.sql Fix NBA simulator missing from dropdown and enum not applied to prod DB 2026-03-16 22:18:50 -07:00
0048_eager_songbird.sql Add Discord webhook notifications for standings updates (#157) 2026-03-17 11:16:36 -07:00
0049_add_admin_picked_by_type.sql Grant sitewide admins commissioner-level access in leagues (#162) 2026-03-18 00:41:56 -07:00
0050_chief_peter_quill.sql Add NHL playoff simulator and fix simulator dropdown (#166) 2026-03-18 01:23:53 -07:00
0051_add_standings_snapshot_unique_index.sql Fix standings snapshot upsert: atomic writes, correct date, and event-driven updates (#177) 2026-03-18 22:15:28 -07:00
0052_new_warbird.sql Fix migration 2026-03-18 22:54:01 -07:00
0053_smooth_kingpin.sql Add standard draft clock mode (#67) (#189) 2026-03-20 21:36:39 -07:00
0054_massive_vulcan.sql Add regular season standings for NBA/NHL (fixes #89) (#192) 2026-03-21 00:12:01 -07:00
0055_special_vampiro.sql Add regular season standings for NBA/NHL (fixes #89) (#192) 2026-03-21 00:12:01 -07:00
0056_jittery_the_fallen.sql Add AFL season + finals simulator (closes #126) (#204) 2026-03-22 01:57:39 -07:00
0057_cultured_doctor_doom.sql Add snooker bracket simulator and Elo ratings admin UI, fixes #119 2026-03-23 08:24:28 -07:00
0058_add_unique_participant_ev.sql Add snooker bracket simulator and Elo ratings admin UI, fixes #119 2026-03-23 08:24:28 -07:00
0059_mysterious_jack_murdock.sql Add tennis Grand Slam simulator with surface Elo ratings, fixes #116 (#216) 2026-03-23 23:59:35 -07:00
0060_omniscient_outlaw_kid.sql Add tennis Grand Slam simulator with surface Elo ratings, fixes #116 (#216) 2026-03-23 23:59:35 -07:00
0061_violet_mephistopheles.sql Add golf qualifying points simulator (Plackett-Luce Monte Carlo) (#223) 2026-03-24 21:46:02 -07:00
0062_add_mlb_bracket_simulator_type.sql Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) 2026-03-25 08:47:02 -07:00
0063_bored_ultimo.sql Add WNBA playoff simulator with SRS-based Elo ratings, fixes #125 (#231) 2026-03-26 00:34:51 -07:00
0064_fuzzy_wolfsbane.sql Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) 2026-03-29 10:27:47 -07:00
0065_kind_mantis.sql Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) 2026-03-29 10:27:47 -07:00
0066_stiff_siren.sql Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) 2026-03-29 10:27:47 -07:00
0067_darts_bracket.sql Add PDC World Darts Championship simulator with Elo-based bracket (#248) 2026-03-31 15:37:28 -07:00
0068_cs2_major_simulator.sql Fix migration 0068: add IF NOT EXISTS to enum ADD VALUE (#269) 2026-04-06 11:12:13 -04:00
0069_draft_window.sql Fix idempotency on 0069 2026-04-06 15:32:39 +00:00
0070_verify_migrations.sql Clean up migration chain and add verification migration (#268) 2026-04-06 10:53:51 -04:00
0071_many_nico_minoru.sql Add NFL season + playoffs Monte Carlo simulator (#272) 2026-04-07 09:39:34 -04:00
0072_jittery_steve_rogers.sql Add NCAA Football CFP simulator (12-team bracket) (#278) 2026-04-08 09:48:32 -04:00
0073_blushing_lady_vermin.sql Add LLWS bracket Monte Carlo simulator (#280) 2026-04-08 16:52:10 -04:00
0074_clammy_tiger_shark.sql feat: add vorp_value column to participants table 2026-04-09 01:57:22 +00:00
0075_chubby_stephen_strange.sql Add audit logging for commissioner actions (#293) 2026-04-13 15:45:39 -07:00
0076_heavy_zemo.sql fix: league settings sports swap and audit log detail improvements (#294) 2026-04-14 21:41:05 -07:00
0077_lively_wolfpack.sql New design (#309) 2026-04-23 13:14:55 -07:00
0078_striped_rick_jones.sql New design (#309) 2026-04-23 13:14:55 -07:00
0079_wide_trauma.sql New design (#309) 2026-04-23 13:14:55 -07:00
0080_chemical_gorilla_man.sql New design (#309) 2026-04-23 13:14:55 -07:00
0081_careless_magdalene.sql Migrate authentication from Clerk to BetterAuth (#324) 2026-04-24 22:00:49 -07:00
0082_stale_pride.sql Migrate authentication from Clerk to BetterAuth (#324) 2026-04-24 22:00:49 -07:00