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
Create API route
Create
app/api/auth/[...nextauth]/route.ts and configure providers (Google, GitHub, etc.).Usage
Server components
Server components
Use
getServerSession() in server components to access the current session.Client components
Client components
Use
useSession() in client components to access the current session.Protect API routes
Protect API routes
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