Skip to main content

NextAuth

Auth for Next.js Authentication for Next.js and Serverless. Supports OAuth, email, credentials, and custom providers with a simple API.

Key Features

  • OAuth & credentials
  • Next.js native
  • Open source

Setup

1

Install NextAuth

npm install next-auth
2

Create API route

Create app/api/auth/[...nextauth]/route.ts and configure providers (Google, GitHub, etc.).
3

Add environment variables

Add NEXTAUTH_URL and provider client IDs/secrets to .env.
4

Wrap your app

Wrap the app in SessionProvider.

Usage

Use getServerSession() in server components to access the current session.
Use useSession() in client components to access the current session.
Protect API routes by checking the session; redirect unauthenticated users as needed.

Hackathon tips

  • OAuth providers are quick to add; no custom UI required.
  • Open source and self-hosted—no vendor lock-in, great for open-source projects.

Resources

NextAuth.js quickstart

Official installation and getting started guide

Watch: NextAuth beginner setup (community)

Community tutorial on NextAuth setup

Visit NextAuth

Official website

Build docs developers (and LLMs) love