NextAuth.js
Complete open-source authentication solution designed for Next.js applications.
3. Used by agents' projects
Dependency in 150 public GitHub projects set up for AI coding agents that we scanned (2.4%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What NextAuth.js does
NextAuth.js is the Next.js package of Auth.js, an open-source auth project that now sits under Better Auth, and its own README steers new projects to Better Auth unless they need a specific gap filled, most notably stateless sessions without a database.
NextAuth.js popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How NextAuth.js is used
- NextAuth.js is a dependency in 150 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (3.1% of the 4,867 JavaScript/TypeScript ones), #2 of 141 in auth and security libraries.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 455; those are left out of every share on this page.
- The most used alternative in our scan is Better Auth (103 projects).
- Projects that use it most often also use Next.js (99.3%), Lucide React (83.3%), clsx (82.0%).
By coding agent
Often used with
NextAuth.js in practice
Strengths
The README says JWTs are encrypted by default (JWE with A256CBC-HS512). It also says CSRF tokens guard the sign-in and sign-out POST routes. The maintainers write that the default cookie policy "aims for the most restrictive policy appropriate for each cookie."
The README says Auth.js "can be used with or without a database." Without one, it describes stateless authentication against backends such as Active Directory or LDAP. With one, it claims built-in support for MySQL, MariaDB, Postgres, Microsoft SQL Server, MongoDB, SQLite and GraphQL, among others.
The README says it is designed to work with any OAuth service that supports 2.0+ or OIDC. It also ships built-in support for many popular sign-in services.
The homepage shows one pattern in four frameworks. Each passes a <code>providers</code> array to a framework wrapper such as <code>SvelteKitAuth</code>, <code>ExpressAuth</code> or <code>QwikAuth$</code>, and imports providers from that package.
Watch out for
The README announces that Auth.js has joined Better Auth. It recommends that new projects start with Better Auth unless they hit a specific feature gap, with stateless sessions without a database named as the main one.
The newest release in the sources is on the 4.x line. An HTML comment in the README, which may be out of date, refers to NextAuth.js v5 as not yet stable. The docs also have a "Migrating to v5" page. Our reading is that it is worth checking which major version a guide assumes before copying from it.
OAuth check cookies are now tied to the provider that set them. The release notes warn that sign-ins started before the upgrade fail one time and succeed on retry.
More about NextAuth.js
Head to head
- NextAuth.js vs Better Auth used together in 3 projects
- NextAuth.js vs Clerk used together in 5 projects
Packages around it
- next: Next.js framework
- clsx: className string builder
- tailwind-merge: Tailwind class conflict merging
- tailwindcss: Utility-first CSS
- class-variance-authority: Component style variants
- lucide-react: Icon set for React
More in Auth and security libraries
Alternatives
NextAuth.js This page
Comprehensive authentication framework for TypeScript with multiple strategies.
Modern authentication and user management SDK for Next.js and React.
Modular authentication middleware for Node.js supporting OAuth, JWT and local strategies.
Get started
Install it.
npm install next-authRules for your agent
## NextAuth.js
- Before adding `next-auth` to a new project, flag that the README recommends Better Auth for new projects unless a specific gap applies, most notably stateless sessions without a database.
- Define config once in `auth.ts` with `NextAuth({ providers: [...] })` and export `auth` and `handlers`. Re-export `handlers` as `GET` and `POST` from `app/api/auth/[...nextauth]/route.ts`.
- To add session fields, use `declare module "next-auth"` module augmentation, not generics. Put JWT fields in `declare module "next-auth/jwt"`.
- When augmenting `Session["user"]`, intersect with `DefaultSession["user"]`, or the default user properties are overwritten.
- Put the module declaration in a file that is included in `tsconfig.json`.
- On the 4.x line, use 4.24.15 or later for the OAuth cookie binding and email normalization fixes. Expect sign-ins in flight during the upgrade to fail once.
- Report suspected vulnerabilities through the Security Policy, not public issues or PRs.