@callmedaniel/nextauth-cli
v1.0.1
Published
π Interactive CLI wizard to scaffold NextAuth.js authentication in seconds
Maintainers
Readme
π NextAuth CLI
Interactive CLI wizard to scaffold NextAuth.js authentication in your Next.js project in seconds!
π Features
β
Interactive Setup Wizard - Answer a few questions and get your auth system in seconds
β
Multiple Providers - Google, GitHub, Apple, Facebook, Email Magic Links, Credentials
β
Session Strategies - JWT (stateless) or Database (stateful)
β
Database Support - Prisma with PostgreSQL, MySQL, MongoDB, SQLite
β
RBAC - Role-Based Access Control utilities included
β
Email Verification - Ready-to-use email verification setup
β
Protected Routes - Middleware and component examples
β
API Protection - Utilities to protect API routes
β
Auto-Install - Optionally auto-install dependencies
π¦ Installation
Global Installation (Recommended)
npm install -g @callmedaniel/nextauth-cliLocal Installation
npm install --save-dev @callmedaniel/nextauth-cliπ― Quick Start
1. Create a Next.js Project
npx create-next-app@latest my-auth-app
cd my-auth-app2. Run the NextAuth CLI
npx @callmedaniel/nextauth-cli3. Answer the Interactive Questions
β Select authentication providers
β Choose session strategy (JWT or Database)
β Select database if needed
β Setup RBAC?
β Setup Email Verification?
β Generate protected routes?
β Install dependencies?4. Configure Environment Variables
Copy .env.example to .env.local and fill in your OAuth credentials:
cp .env.example .env.local5. Start Your Development Server
npm run devVisit http://localhost:3000/auth/signin to see your auth system in action!
π Generated Files
The CLI generates the following structure:
app/
βββ api/auth/[...nextauth]/
β βββ route.ts # NextAuth configuration
βββ dashboard/
β βββ page.tsx # Protected route example
components/
βββ auth/
β βββ SignIn.tsx # Sign-in component
lib/
βββ auth/
β βββ rbac.ts # Role-Based Access Control
β βββ email-verification.ts # Email verification utilities
β βββ protectedApi.ts # API protection utilities
middleware.ts # Route protection middleware
prisma/
βββ schema.prisma # Database schema (if DB selected)
.env.example # Environment variables templateπ Authentication Providers
Google OAuth
Requires: GOOGLE_ID, GOOGLE_SECRET
GitHub OAuth
Requires: GITHUB_ID, GITHUB_SECRET
Apple OAuth
Requires: APPLE_ID, APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_PRIVATE_KEY
Facebook OAuth
Requires: FACEBOOK_ID, FACEBOOK_SECRET
Email Magic Links
Requires: EMAIL_SERVER, EMAIL_FROM
Credentials (Username/Password)
No additional setup required. Implement your own authorization logic.
π‘οΈ RBAC (Role-Based Access Control)
The CLI generates RBAC utilities for role-based access control:
import { hasPermission, hasRole } from '@/lib/auth/rbac';
// Check if user has a specific permission
if (hasPermission(userRole, 'write:all')) {
// Allow action
}
// Check if user has a specific role
if (hasRole(userRole, 'admin')) {
// Admin-only action
}π§ Email Verification
The CLI includes email verification utilities:
import { generateVerificationToken, verifyEmailToken } from '@/lib/auth/email-verification';
// Generate a verification token
const token = generateVerificationToken('[email protected]');
// Verify the token
const result = verifyEmailToken(token);
if (result.valid) {
console.log('Email verified:', result.email);
}π Protected Routes
The generated middleware protects routes automatically:
// middleware.ts already set up to protect:
// - /dashboard/*
// - /profile/*
// - /admin/*π οΈ API Route Protection
Protect your API routes:
import { requireAuth } from '@/lib/auth/protectedApi';
export async function GET(request) {
const session = await requireAuth(request);
if (session instanceof Response) return session; // Unauthorized
// Your protected API logic
return Response.json({ message: 'Success' });
}π NextAuth Documentation
For more information about NextAuth.js, visit:
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
π License
MIT License - see LICENSE file for details
π Support
If you have questions or issues:
- Check the NextAuth.js Documentation
- Open an issue on GitHub
- Start a discussion on GitHub Discussions
Made with β€οΈ by callmedaniel-del
