1.0.2 ⢠Published 5 months ago
next-prisma-drizzle-auth v1.0.2
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
- Create a new project using our CLI:
npx next-prisma-drizzle-auth my-app
Select your preferred ORM when prompted (Prisma or Drizzle)
Navigate to the project directory:
cd my-app
Configuration
- 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=""
- Generate AUTH_SECRET:
npx auth secret
Set up OAuth providers:
- Create a Google OAuth app: Google Cloud Console
- Create a GitHub OAuth app: GitHub Developer Settings
Get your Resend API key from Resend
Database Setup
For Prisma:
- Update your DATABASE_URL in
.env
- Generate Prisma client:
npx prisma generate
- Push the schema to your database:
npx prisma db push
For Drizzle:
- Set your DATABASE_TYPE in
.env
("postgres", "mysql", or "sqlite") - Update your DATABASE_URL in
.env
- 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
- Users can sign up using email/password or OAuth
- Email verification is required for email/password signup
- Password reset functionality available
- Two-factor authentication (2FA) is optional for email/password signup
- OAuth users are automatically verified
- 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!