Auth System Migration
Instructions
- •Analyze the current authentication system (NextAuth, Auth.js, custom auth, etc.)
- •Plan the migration strategy considering user data, sessions, and existing providers
- •Create a schema mapping between the old system and Better Auth
- •Prepare database migration scripts
- •Migrate user data while preserving security
- •Update application code to use Better Auth
- •Test the migration thoroughly
Migration Steps
- •Document the current auth system setup
- •Create a backup of the existing authentication data
- •Set up Better Auth alongside the current system
- •Map user data fields from old system to Better Auth schema
- •Create migration scripts for users, sessions, and accounts
- •Handle password hash compatibility if needed
- •Update API routes and middleware
- •Test authentication flows end-to-end
- •Switch over gradually with feature flags if possible
Common Migration Scenarios
From NextAuth.js:
- •Migrate User, Account, Session, and VerificationToken tables
- •Convert password hashes if needed (NextAuth typically uses bcrypt)
- •Migrate OAuth account connections
- •Update next-auth client calls to Better Auth client calls
From Custom Auth:
- •Map custom user schema to Better Auth schema
- •Handle custom password hashing algorithms
- •Migrate session management system
- •Update authentication middleware/guards
Data Migration Considerations
- •Password hashes may need conversion or re-hashing
- •OAuth provider tokens need to be preserved
- •Session data needs to be compatible
- •User roles/permissions need to be mapped
- •Account linking for social providers