migrate-to-better-auth
Migrate to Better-Auth
Migrate any auth system to better-auth incrementally. Never rewrite everything at once — plan first, execute one phase at a time.
Depends on:
better-auth/skillsfor setup patterns (npx skills add better-auth/skills). This skill handles the migration layer on top.
Quick Start
- Audit the existing auth setup.
- Prompt the user to select better-auth features.
- Generate a migration plan via
/refactor-codebase. - Execute phases: schema → server config → routes → client → seed data.
Workflow
1. Audit existing auth
Identify: auth library, auth methods, DB schema (tables + column names + types), ORM/adapter, seed files, and framework. Summarize to the user before proceeding.
2. Prompt user to select features
Present this checklist and ask for confirmation:
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. Map old schema → better-auth schema
Produce a field mapping table before touching code. Flag breaking type changes — especially emailVerified Date → boolean. See REFERENCE.md for mappings by source library.
4. Generate the migration plan
Invoke /refactor-codebase with a Refactor PRD covering: current library + schema, target better-auth config, the mapping table, and seed files. Standard phases:
- Install & scaffold —
better-auth, schema generation, env vars - Schema migration — alter DB tables
- Server config — write
auth.tswith confirmed features/plugins - Route handlers — replace old routes with
auth.handler - Client — replace session hooks with
authClient - Seed data — update fixtures (step 5)
- Cleanup — remove old auth library
5. Refactor seed data
If seed files exist, invoke /refactor-codebase scoped to those files: rename columns, coerce emailVerified to boolean, add required fields (createdAt, updatedAt, accountId, providerId). Keep data behavior identical — no new users or roles unless asked.
6. Verify after each phase
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"}'
Report results before starting the next phase.
Guardrails
- Do not remove the old auth library until all phases pass verification.
- Never silently cast
emailVerifiedDate → boolean — write an explicit migration script. - Flag missing OAuth env vars before starting; do not proceed until user confirms.
- If no auth tests exist, recommend a smoke test as Phase 0.
References
- REFERENCE.md — schema mappings per library, ORM adapter snippets, seed before/after examples, env var checklist.
better-auth/skills— framework setup (npx skills add better-auth/skills).
More from rockclaver/systemcraft
code-graph
Builds and maintains a `.claude/codegraph.md` index of a codebase — a structured map of every module with purpose, key exports, and dependencies — so the agent can navigate any repo by reading one file instead of scanning dozens. Use when starting work on an unfamiliar codebase, when asked to index a repo, when context costs are high from repeated scans, or at the start of any task that will touch multiple files.
14find-code
Locate files and code using grep and shell scripts — never by AI scanning. Returns exact file paths and line numbers so the agent can jump directly to the location. Use whenever the agent needs to find a function, class, variable, import, file, or any pattern in the codebase. Code and file discovery must always be a tool call, never an AI guess.
14grill-me
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
13prd-to-plan
Turn a PRD into a multi-phase implementation plan using tracer-bullet vertical slices, saved as a local Markdown file in ./plans/. Use when user wants to break down a PRD, create an implementation plan, plan phases from a PRD, or mentions "tracer bullets".
13write-a-prd
Create a PRD through user interview, codebase exploration, and module design, then submit as a GitHub issue. Use when user wants to write a PRD, create a product requirements document, or plan a new feature.
13design-api
Design and implement consistent, DRY REST API endpoints for database models — handlers, routing, validation, error responses, and shared utilities — then generate test coverage for every endpoint. Use when the user asks to write an API, add endpoints for a model, build a REST layer, or create CRUD routes.
13