$ show nextauthjs/next-auth
This is a monorepo for Auth.js (formerly NextAuth.js), a framework-agnostic authentication library for web applications. The core engine (`@auth/core`) handles OAuth/OIDC, email/passwordless, credentials, and WebAuthn/Passkey authentication flows. It provides a unified API for session management (JWT or database-backed), CSRF protection, and cookie handling. The library is designed to be integrated into multiple frameworks via separate packages: `@auth/nextjs`, `@auth/sveltekit`, `@auth/express`, `@auth/qwik`, and `@auth/solid-start`. Each framework package adapts the core `Auth` function to the framework's request/response model, offering server-side handlers, middleware, and client-side hooks. The repository also includes over 80 built-in OAuth/OIDC provider definitions (e.g., Google, GitHub, Discord, Auth0) and 20+ database adapters (e.g., Prisma, Drizzle, MongoDB, PostgreSQL, DynamoDB) that implement a standard `Adapter` interface for user persistence. The project is now part of Better Auth, and the README recommends new projects use Better Auth unless specific feature gaps exist. The monorepo contains development apps, example applications, and a comprehensive documentation site built with Nextra.
The LLM identified 4 files worth highlighting for reuse:
A generic deep-merge utility for combining default configuration objects with user-provided options. It handles nested objects, arrays, and primitive values without mutating the source. The function is self-contained, uses TypeScript generics, and is used extensively across the codebase to merge provider defaults, adapter options, and framework configs. It can be extracted into any project requiring safe config merging.
Implements cookie parsing, serialization, and a `SessionStore` class that manages session tokens with automatic chunking for large JWTs (respecting the 4096-byte cookie limit). It handles cleaning, setting, and clearing cookies across multiple chunks. The code is isolated from the rest of the auth logic and can be reused in any Node.js/Edge runtime that needs cookie-based session management with chunking.
Defines a hierarchical set of error classes extending `AuthError`, each with a static `type` string and `kind` property (e.g., `OAuthSignInError`, `AccessDenied`, `EmailSignInError`). This pattern enables consistent error handling across authentication flows and allows client-side redirection based on error type. The classes are self-contained and can be extracted to provide structured error types in any application.
A reusable test suite (`runBasicTests`) that validates any database adapter implementing the standard `Adapter` interface. It creates users, accounts, sessions, verification tokens, and runs CRUD operations to ensure correct behavior. The harness is self-contained and can be imported by any adapter package; it uses fixtures and mocks for a consistent testing environment. This pattern is highly valuable for projects that need to guarantee adapter parity across multiple databases.