next-auth
Complete, open-source authentication for Next.js — OAuth, email, and credentials with almost no boilerplate.
next-auth
ReactComplete, open-source authentication for Next.js — OAuth, email, and credentials with almost no boilerplate.
Fit
Bundle (gzip)
82.5 kB
282.8 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Rolling your own auth means handling OAuth callbacks, session cookies, CSRF, token rotation, and secure storage — a lot of surface area to get wrong. Hosted providers solve it but add cost, lock-in, and a redirect flow you don't fully control.
What It Does
NextAuth (Auth.js) drops into a Next.js app and handles sign-in with 80+ OAuth providers, magic-link email, and credentials out of the box. It manages secure, encrypted session cookies (or database sessions), CSRF protection, and callbacks, exposing a simple useSession hook and server helpers.
Installation
npm install next-authUsage Example
// app/api/auth/[...nextauth]/route.js
import NextAuth from 'next-auth';
import GitHub from 'next-auth/providers/github';
const handler = NextAuth({
providers: [
GitHub({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }),
],
});
export { handler as GET, handler as POST };Related packages
Fast, composable command palette for React — keyboard-driven search UI with fuzzy filtering and accessible markup out of the box.
@dnd-kit/coreReactModern, accessible drag-and-drop toolkit for React — fully customizable with keyboard support, collision detection, and zero dependencies.
embla-carousel-reactReactLightweight, extensible carousel library for React — smooth scrolling, touch/mouse drag, and full CSS control without prescribing markup.
flagsReactProvider-agnostic feature flags SDK for Next.js and React — toggle features without redeploying.
framer-motionReactProduction-ready declarative animation library for React — gestures, layout animations, and scroll-driven effects with a clean API.