Complete Setup Example

A complete, production-ready authentication setup with all features enabled.

What You'll Build

āœ…

Login & Registration

Complete auth flow with email verification

šŸ‘„

Organizations

Multi-tenant with organization switching

šŸ›”ļø

Security

Account lockout, 2FA, restrictions

āš™ļø

Admin Dashboard

Manage users and security settings

Step 1: Initial Setup

Terminal

Step 2: Configure Environment

Create a .env file:

.env

Step 3: Set Up NextAuth API Route

app/api/auth/[...nextauth]/route.ts

Step 4: Create Login Page

app/login/page.tsx

Step 5: Create Dashboard

app/dashboard/page.tsx

Step 6: Add Middleware Protection

middleware.ts

Step 7: Create Admin Panel

app/admin/security/page.tsx

Final Project Structure

my-auth-app/
ā”œā”€ā”€ app/
│   ā”œā”€ā”€ api/
│   │   └── auth/
│   │       └── [...nextauth]/
│   │           └── route.ts
│   ā”œā”€ā”€ login/
│   │   └── page.tsx
│   ā”œā”€ā”€ dashboard/
│   │   └── page.tsx
│   ā”œā”€ā”€ admin/
│   │   └── security/
│   │       └── page.tsx
│   ā”œā”€ā”€ layout.tsx
│   └── page.tsx
ā”œā”€ā”€ prisma/
│   ā”œā”€ā”€ schema.prisma
│   └── seed.ts
ā”œā”€ā”€ middleware.ts
ā”œā”€ā”€ .env
ā”œā”€ā”€ package.json
└── next.config.js

Running the Application

1. Start Development Server

npm run dev

2. Visit Login Page

Navigate to http://localhost:3000/login

3. Use Demo Credentials

  • Email: owner@example.com
  • Password: password123

4. Access Admin Panel

Navigate to http://localhost:3000/admin/security

Next Steps

Download Complete Example

Get the full source code with all features configured