Skip to main content
This guide walks through migrating a project from Auth.js (formerly NextAuth.js) to Better Auth. The two libraries have different design philosophies, so the migration requires some planning.
If your Auth.js setup is working well there is no urgent need to migrate. Better Auth continues to add features previously exclusive to Auth.js, and we welcome the opportunity to earn your adoption on new or greenfield projects.
1

Create the Better Auth instance

Follow the installation guide to add Better Auth to your project. Here is a side-by-side comparison of a minimal GitHub OAuth config:
auth.ts
2

Create the client instance

Better Auth ships a separate client package for browser/React usage:
auth-client.ts
3

Update the route handler

Rename /app/api/auth/[...nextauth] to /app/api/auth/[...all], then update route.ts:
app/api/auth/[...nextauth]/route.ts
4

Migrate client-side session management

Sign in

Sign out

Get session (client)

5

Migrate server-side session management

Get session (server)

Sign out (server)

6

Protect routes

Better Auth recommends checking the session on each page or route rather than relying on middleware for full authorization.
app/dashboard/page.tsx
7

Migrate the database

If you were using the Auth.js database session strategy you will need to migrate your data. The table below summarises the schema differences.

User table

Session table

Account table

VerificationToken → Verification


Wrapping up

For a full implementation example see the Next.js demo app. Need help? Join the community or email contact@better-auth.com.