Next.js 16 + Auth.js v5 + Prisma authentication starter with GitHub/Google OAuth, email/password login, and protected routes.
Built from the auth system powering 32blog.com.
- Auth.js v5 (NextAuth.js) — JWT sessions, multiple providers
- OAuth — GitHub and Google sign-in out of the box
- Credentials — Email/password registration with bcrypt hashing
- Prisma ORM — PostgreSQL adapter with User, Account, Session models
- Protected routes — Proxy-based auth guard on
/dashboard - Server Actions — Form handling with Zod validation
- React 19 —
useActionStatefor form state management - Tailwind CSS v4 — Clean, responsive UI
git clone https://github.com/omitsu-dev/nextjs-auth-starter.git
cd nextjs-auth-starter
npm installcp .env.example .envEdit .env:
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
AUTH_SECRET="generate-with-npx-auth-secret"
AUTH_GITHUB_ID="your-github-oauth-app-id"
AUTH_GITHUB_SECRET="your-github-oauth-app-secret"
AUTH_GOOGLE_ID="your-google-client-id"
AUTH_GOOGLE_SECRET="your-google-client-secret"Generate AUTH_SECRET:
npx auth secretnpx prisma db pushnpm run devOpen http://localhost:3000.
├── app/
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Landing page
│ ├── (auth)/
│ │ ├── login/page.tsx # Login page
│ │ └── register/page.tsx # Registration page
│ ├── dashboard/page.tsx # Protected dashboard
│ └── api/auth/[...nextauth]/
│ └── route.ts # Auth.js API route
├── components/
│ ├── LoginForm.tsx # Email/password login form
│ ├── RegisterForm.tsx # Registration form
│ └── OAuthButtons.tsx # GitHub/Google OAuth buttons
├── lib/
│ ├── auth.ts # Auth.js configuration
│ ├── actions.ts # Server Actions (login, register)
│ └── db.ts # Prisma client singleton
├── prisma/
│ └── schema.prisma # Database schema
└── proxy.ts # Route protection (Next.js 16)
Unauthenticated → /login or /register
├── OAuth (GitHub/Google) → Auth.js callback → /dashboard
└── Credentials (email/password) → Server Action → /dashboard
/dashboard (protected)
└── Requires session → redirects to /login if not authenticated
- Go to github.com/settings/developers
- New OAuth App
- Set callback URL:
http://localhost:3000/api/auth/callback/github - Copy Client ID and Client Secret to
.env
- Go to console.cloud.google.com/apis/credentials
- Create OAuth 2.0 Client ID (Web application)
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google - Copy Client ID and Client Secret to
.env
- Import the provider in
lib/auth.ts:
import Discord from "next-auth/providers/discord";- Add it to the
providersarray:
providers: [GitHub, Google, Discord, Credentials({...})],- Add env variables:
AUTH_DISCORD_ID,AUTH_DISCORD_SECRET
| Package | Version |
|---|---|
| Next.js | 16.x |
| Auth.js (next-auth) | 5.x beta |
| Prisma | 6.x |
| React | 19.x |
| Tailwind CSS | 4.x |
| Zod | 3.x |
| bcryptjs | 2.x |
- Claude Code × Next.js: Stop AI-Generated App Router Mistakes — Common App Router pitfalls and how to avoid them