# NextAuth.js — card for AI agents

Complete open-source authentication solution designed for Next.js applications.

Category: Auth and security libraries · npm package `next-auth` · latest version 4.24.15 (checked 2026-11-01)
Install: `npm install next-auth`
License: ISC (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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.

## What it is
- NextAuth.js is published on npm as `next-auth`. It is the Next.js entry point to Auth.js, which the README describes as "a set of open-source packages that are built on standard Web APIs for authentication in modern applications with any framework on any platform in any JS runtime." The GitHub repository was created on 2018-01-27 and is ISC licensed.
- In the site's Next.js example, an `auth.ts` file calls `NextAuth({ providers: [GitHub] })`, which returns `auth` and `handlers`. A catch-all route at `app/api/auth/[...nextauth]/route.ts` then exports the handlers as `GET` and `POST`. Sibling packages such as `@auth/sveltekit`, `@auth/express` and `@auth/qwik` use the same pattern.
- The README sums up the project as "Open Source. Full Stack. Own Your Data." It lists OAuth and OIDC, email and passwordless sign-in, passkeys, and an optional database. The project's direction has changed. The site now reads "The Auth.js project is now part of Better Auth", and the docs navigation opens with a "Migrate to Better Auth" page.

## Caveats
- The maintainers point new projects to Better Auth: 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.
- Mixed signals on v5: 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.
- Upgrading to 4.24.15 fails in-flight sign-ins once: 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.
- Extending Session can drop the default fields: When you augment the `Session` user type, TypeScript overwrites the existing properties. The docs' examples keep the defaults by intersecting with `DefaultSession["user"]`.
- uuid 14.x broke require() on older Node: The 4.24.15 notes say the `uuid` 14.x line is ESM-only and broke `require()` on Node versions below 20.19. The release pins `uuid` to `^11.1.1` to restore CommonJS compatibility.

## Numbers (AgentGid data)
- Gid Score: 75.3 (#198 of all tools, 5 of 141 in its category)
- Used in 150 public projects set up for AI coding agents (2.4%)
- Downloads last week: 9,439,943 (as of 2026-11-24), +41.9% over 4 weeks
- GitHub stars: 28,389 (as of 2026-11-24)
- Last push: 2026-07-22

## Often used with
Next.js 99.3%, Lucide React 83.3%, clsx 82.0%, Tailwind Merge 78.0%, React 99.3%, Tailwind CSS 97.3%

## Checked alternatives (same job)
- Better Auth: https://agentgid.com/tools/better-auth/agent.md
- Clerk: https://agentgid.com/tools/clerk/agent.md
- Passport.js: https://agentgid.com/tools/passport/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/next-auth/
- Homepage: https://authjs.dev
- Repository: https://github.com/nextauthjs/next-auth
- Source: https://github.com/nextauthjs/next-auth#readme
- Source: https://github.com/nextauthjs/next-auth
- Source: https://github.com/nextauthjs/next-auth/releases
- Source: https://authjs.dev
- Source: https://authjs.dev/getting-started/typescript

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
