Skip to content

akdevv/next-auth-starter

Repository files navigation

πŸš€ Next Auth Starter

A production-ready Next.js authentication starter with modern features, comprehensive security, and excellent developer experience.

✨ Features

πŸ” Authentication & Security

  • Multiple Auth Methods: Email/password, Google OAuth, magic links
  • Two-Factor Authentication (2FA): TOTP with backup codes
  • Session Management: Secure sessions with device tracking
  • Email Verification: Automatic email verification flow
  • Password Security: bcrypt hashing with strength validation
  • Rate Limiting: Built-in protection against brute force attacks

πŸ“§ Email System

  • Transactional Emails: Welcome, verification, password reset
  • React Email Templates: Beautiful, responsive email designs
  • Security Notifications: Login alerts and suspicious activity
  • Resend Integration: Reliable email delivery service

πŸ›‘οΈ Advanced Security

  • CSRF Protection: Built-in cross-site request forgery protection
  • Secure Headers: Comprehensive security headers configuration
  • Input Validation: Zod schemas for type-safe validation
  • Audit Logging: Complete authentication event tracking

πŸ‘€ User Management

  • Profile Management: User profiles with avatar support
  • Device Management: View and revoke active sessions
  • Account Recovery: Multiple recovery options including backup codes
  • Account Deletion: GDPR-compliant data removal

🎯 Why This Project?

Building authentication from scratch is complex, time-consuming, and security-critical. This starter provides:

  • βœ… Production-ready authentication flows
  • βœ… Security best practices built-in
  • βœ… Modern tech stack with excellent DX
  • βœ… Comprehensive documentation and examples
  • βœ… Type-safe development experience
  • βœ… Scalable architecture for growth

πŸ› οΈ Tech Stack

Core Framework

Authentication & Security

UI & Styling

Email & Communication

Development Tools

  • Bun - Fast JavaScript runtime & package manager
  • ESLint - Code linting and quality
  • Zod - TypeScript-first schema validation

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ or Bun
  • PostgreSQL database (we recommend Supabase)
  • Google Cloud Console account (for OAuth)
  • Resend account (for emails)

1. Clone & Install

git clone https://github.com/akdevv/next-auth-starter.git
cd next-auth-starter

# Install dependencies (recommended: use Bun)
bun install
# or npm install

2. Environment Setup

# Copy environment template
cp .env.example .env

# Fill in your environment variables
# See docs for detailed setup: /docs/getting-started/environment-variables

Required environment variables:

NEXT_PUBLIC_BASE_URL="http://localhost:3000"
AUTH_SECRET="your-secret-key"
DATABASE_URL="your-postgresql-url"
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
NEXT_PUBLIC_RESEND_API_KEY="your-resend-api-key"

3. Database Setup

# Generate Prisma client
bun prisma generate

# Push schema to database
bun prisma db push

# (Optional) Seed database
bun prisma db seed

4. Start Development

bun dev

Visit http://localhost:3000 - your auth system is ready! πŸŽ‰

πŸ“– Documentation

Complete documentation is available at /docs when running the project:

πŸ› οΈ Development

Available Scripts

# Development
bun dev              # Start development server with Turbopack
bun build            # Build for production
bun start            # Start production server
bun lint             # Run ESLint

# Database
bun prisma studio    # Open database browser
bun prisma migrate   # Run migrations
bun prisma generate  # Generate Prisma client
bun prisma reset     # Reset database

# Email Development
bun email            # Preview emails locally

Project Structure

next-auth-starter/
β”œβ”€β”€ app/                 # Next.js App Router
β”‚   β”œβ”€β”€ api/            # API routes
β”‚   β”œβ”€β”€ auth/           # Authentication pages
β”‚   └── profile/        # User profile pages
β”œβ”€β”€ components/         # React components
β”‚   β”œβ”€β”€ auth/          # Auth-specific components
β”‚   β”œβ”€β”€ ui/            # shadcn/ui components
β”‚   └── shared/        # Shared components
β”œβ”€β”€ content/           # Documentation (MDX)
β”œβ”€β”€ emails/            # Email templates
β”œβ”€β”€ lib/               # Utilities and configurations
β”œβ”€β”€ prisma/            # Database schema and migrations
β”œβ”€β”€ server/            # Server actions and utilities
└── schema/            # Zod validation schemas

πŸ” Security Features

  • πŸ›‘οΈ CSRF Protection - Built-in token validation
  • πŸ”’ Session Security - Secure cookie-based sessions
  • ⚑ Rate Limiting - Prevent brute force attacks
  • πŸ“§ Email Verification - Verify email ownership
  • πŸ” 2FA Support - TOTP with QR codes
  • πŸ”‘ Backup Codes - Emergency account recovery
  • 🚨 Security Alerts - Login notifications
  • πŸ”„ Session Management - Multi-device session control

🌟 Production Ready

This starter includes production-ready features:

  • Performance Optimized - Server-side rendering, code splitting
  • SEO Friendly - Meta tags, structured data
  • Accessibility - WCAG compliant components
  • Mobile Responsive - Works on all devices
  • Error Handling - Graceful error boundaries
  • Monitoring Ready - Built-in logging and analytics hooks

πŸš€ Deployment

Deploy to your favorite platform:

Vercel (Recommended)

vercel deploy

Docker

docker build -t next-auth-starter .
docker run -p 3000:3000 next-auth-starter

Other Platforms

  • Netlify - Static export support
  • Railway - Database included
  • AWS/GCP/Azure - Serverless functions

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

  • πŸ“– Documentation: Visit /docs in your running project
  • πŸ’¬ Issues: GitHub Issues
  • πŸ› Bug Reports: Use issue templates
  • πŸ’‘ Feature Requests: Open a discussion

Built with ❀️ by the community. Star ⭐ if this project helped you!

About

Next.js Authentication Starter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published