Migrate to better-auth one phase at a time.
Workflow
1. Audit
Auth library, methods, schema, ORM, seed files.
2. Select features
Auth methods: email/password, OAuth (which providers?), magic link, passkeys, phone/OTP, anonymous
Plugins: 2FA, organization/multi-tenant, admin roles, API keys, SSO/OIDC, JWT, HIBP breach detection
Session: database-backed (default) | Redis-backed
3. Plan
Map fields first (REFERENCE.md); run /refactor-codebase with the mapping, config, seed. Phases:
- Install & scaffold —
better-auth, schema, env vars - Schema migration — alter DB tables
- Server config —
auth.ts - Route handlers —
auth.handler - Client —
authClienthooks - Seed data — update fixtures
- Cleanup — remove old library
4. Seed data
Rename columns, coerce emailVerified to boolean, add createdAt/updatedAt/accountId/providerId.
5. Verify
npx tsc --noEmit && npm test
curl -X POST http://localhost:3000/api/auth/sign-in/email \
-H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password"}'
Guardrails
- Keep the old library until phases verify; never silently cast
emailVerifiedto boolean. - Flag missing OAuth env vars.
- No auth tests? Add a Phase 0 smoke test.
References
- REFERENCE.md — schema mappings, ORM snippets, env vars.
better-auth/skills— setup (npx skills add better-auth/skills).