Auth
Auth.js
An open source authentication library for web apps (formerly NextAuth.js), with OAuth providers and sessions.
What it is
Auth.js began as NextAuth.js for Next.js and later became framework-agnostic. The library lives inside your app, and user data is stored in your database through adapters.
It has ready providers (Google, GitHub and dozens more), email magic-link sign-in, credentials login and built-in session handling: a JWT cookie or database sessions.
It is a good choice if you want control and no per-user fee. Responsibility for configuring security correctly is yours.
Use it when
- A Next.js or SvelteKit app with social login.
- You want control over data without a separate identity server.
- Small and medium projects on a limited budget.
Avoid it when
- You need enterprise SSO, SAML and organization management out of the box: Auth0, Clerk, Keycloak.
- Mobile apps and service-to-service authorization.
Key concepts
- Provider
- An external sign-in configuration (Google, GitHub).
- Adapter
- A layer that stores users and sessions in your database.
- Session strategy
- A JWT in a cookie or a session record in the database.
- Callbacks
jwtandsessionhooks for adding custom fields.
Example
Interview questions
1. JWT or database sessions?
A JWT session needs no database hit per request but is harder to revoke. A database session revokes instantly but adds a storage lookup.
2. What are adapters for?
To store users, accounts and sessions in your database (Prisma, Drizzle and others). Without an adapter only the JWT strategy is available.
3. Is the credentials provider safe?
It works, but you own password hashing, attempt limiting and resets. For most cases social providers or email links are better.
Related technologies
- Next.jsA full-stack React framework: routing, SSR, static generation, API routes and server components.
- OAuth 2.0A delegated authorization standard: an app gets limited access to a user's resources without their password.
- OpenID ConnectAn authentication layer on top of OAuth 2.0: the client receives an ID token with user information.
- JWTA compact signed token in JSON format that carries claims about a user or permissions.
- PrismaAn ORM for Node.js and TypeScript with a schema file, a generated type-safe client and migrations.
- ClerkA managed authentication service with ready React components for sign-in, profile and organizations.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).