1.0.2 • Published 5 months ago

next-prisma-drizzle-auth v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

next-prisma-drizzle-auth

Authentication template for Next.js using Prisma and Drizzle. A modern authentication template built with Next.js 15, featuring both Prisma and Drizzle ORM options. This template includes email/password authentication, OAuth providers (Google, GitHub), and email verification.

Key Features

Authentication & Security

  • šŸ” Next-auth v5 (Auth.js) with robust authentication
  • šŸ”‘ Credentials & OAuth Providers (Google, GitHub)
  • āœ‰ļø Email verification
  • šŸ“± Two-factor authentication (2FA)
  • šŸ”’ Forgot password functionality

User Management

  • šŸ‘„ User roles (Admin & User)
  • 🚪 Login/Logout capabilities
  • šŸ›‚ Role-based access control
  • šŸ‘¤ User hooks and utilities

Components

  • šŸ”“ Login (redirect or modal)
  • šŸ“ Registration
  • šŸ¤” Password recovery
  • āœ… Verification
  • āš ļø Error handling

Development & Extensibility

  • šŸš€ Next.js 15 with server actions
  • šŸ” Middleware integration
  • šŸ“ˆ Extended next-auth session management
  • šŸ›”ļø API & server action protection

Settings & Customization

  • šŸ”‘ Password modification
  • šŸ”” Two-factor auth toggle
  • šŸ”„ User role management (dev purposes)

Technical Highlights

  • šŸŽØ Tailwind CSS styling
  • šŸŽÆ TypeScript support
  • šŸ“± Responsive design

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Database (PostgreSQL, MySQL, or SQLite)
  • Resend account for email services

Installation

  1. Create a new project using our CLI:
npx next-prisma-drizzle-auth my-app
  1. Select your preferred ORM when prompted (Prisma or Drizzle)

  2. Navigate to the project directory:

cd my-app

Configuration

  1. Set up your environment variables in .env:
DATABASE_URL=""
AUTH_SECRET=""
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
RESEND_API_KEY=""
NEXT_PUBLIC_APP_URL="http://localhost:3000"
RESEND_EMAIL=""
  1. Generate AUTH_SECRET:
npx auth secret
  1. Set up OAuth providers:

  2. Get your Resend API key from Resend

Database Setup

For Prisma:

  1. Update your DATABASE_URL in .env
  2. Generate Prisma client:
npx prisma generate
  1. Push the schema to your database:
npx prisma db push

For Drizzle:

  1. Set your DATABASE_TYPE in .env ("postgres", "mysql", or "sqlite")
  2. Update your DATABASE_URL in .env
  3. Push the schema to your database:
npm run db:push

Running the Application

Start the development server:

npm run dev

Visit http://localhost:3000 to see your application.

Project Structure

src
ā”œā”€ā”€ actions           # Server Actions
│
ā”œā”€ā”€ app
│   ā”œā”€ā”€ auth          # Authentication Routes
│   │
|   ā”œā”€ā”€ api           # API Routes
|
ā”œā”€ā”€ components
│   ā”œā”€ā”€ auth          # Authentication Components
│   ā”œā”€ā”€ ui.tsx        # Shadcn UI Components
│
ā”œā”€ā”€ db                # Database
|
ā”œā”€ā”€ hooks
|
ā”œā”€ā”€ lib
│   ā”œā”€ā”€ shchemas      # Authentication Schemas using Zod
│   ā”œā”€ā”€ auth          # Authentication Utilities
│   ā”œā”€ā”€ mail          # Email Utilities
│   ā”œā”€ā”€ tokens        # Token Utilities
|
ā”œā”€ā”€ middleware.ts     # Middleware Configuration for Next-Auth
|
ā”œā”€ā”€ auth.ts           # Next-Auth Configuration
|
ā”œā”€ā”€ next-auth.d.ts     # Next-Auth Custom Types
|
ā”œā”€ā”€ routes            # Next-Auth Routes

Authentication Flow

  1. Users can sign up using email/password or OAuth
  2. Email verification is required for email/password signup
  3. Password reset functionality available
  4. Two-factor authentication (2FA) is optional for email/password signup
  5. OAuth users are automatically verified
  6. Session management handled by Next-Auth

Repository

This project is maintained at https://github.com/husseinmoqbel7/next-prisma-drizzle-auth

Author

Hussein Moqbel - https://github.com/husseinmoqbel7

Support

If you find this helpful, please give it a ā­ļø on GitHub!

Acknowledgments

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago