Auth RBAC
A complete Role-Based Access Control authentication system with advanced security features
RBAC Authentication System
A comprehensive, production-ready authentication system with Role-Based Access Control (RBAC), built with modern security practices and seamless integration using Next.js Server Actions.

This authentication system provides enterprise-grade security with minimal setup. Perfect for applications requiring user management, role-based permissions, and advanced security features using Next.js Server Actions for optimal performance.
Features
- Complete Authentication Flow - Login, Register, Password Reset
- Role-Based Access Control - Admin/User roles with extensible system
- Two-Factor Authentication - Email-based 2FA for enhanced security
- Email Verification - Secure email confirmation system
- Profile Management - Image upload with Cloudinary integration
- OAuth Integration - Google & GitHub authentication
- Session Management - Secure session handling with NextAuth.js
- Email Services - Password reset and verification emails
- Modern UI - Beautiful components with AxionJS
- Server Actions - Type-safe server-side operations without API routes
Tech Stack
- Framework: Next.js 14+ with App Router
- Authentication: NextAuth.js v5
- Database: PostgreSQL with Prisma ORM
- Validation: Zod schemas
- UI Components: AxionJS + Tailwind CSS
- Email: React Email templates
- File Upload: Cloudinary integration
- Security: bcryptjs for password hashing
- Server Actions: Type-safe server operations
Installation
Core Components
Authentication Forms
The system includes pre-built, accessible forms for all authentication flows:
Role-Based Protection
Protect routes and components based on user roles:
Settings Management
Complete user settings with profile management:
Server Actions Architecture
This system leverages Next.js Server Actions for type-safe, secure server-side operations without the need for API routes:
Authentication Actions
Profile Management Actions
Advanced Features
Two-Factor Authentication
Automatic 2FA setup with email-based verification using Server Actions:
Email Verification
Secure email verification for new registrations and email changes:
Profile Image Upload
Integrated Cloudinary support with Server Actions:
Extending Roles
Add custom roles to your application:
Security Features
This system implements multiple security layers to protect your application and users using Server Actions for enhanced security.
- Server-Side Validation: All operations validated on server using Zod schemas
- Password Hashing: bcryptjs with salt rounds
- CSRF Protection: Built-in NextAuth.js protection
- Session Security: Secure HTTP-only cookies
- Rate Limiting: Built-in protection against brute force
- Email Verification: Prevents fake account creation
- Token Expiration: All tokens have configurable expiry
- OAuth Security: Secure third-party authentication
- Type Safety: Full TypeScript support with Server Actions
Server Actions vs API Routes
This system uses Server Actions instead of traditional API routes for several advantages:
Authentication Flow
The complete authentication flow using Server Actions:
Customization
Styling
All components use Tailwind CSS and can be easily customized:
Email Templates
Customize email templates in /components/emails/
:
Database Schema Extensions
Extend the user model with additional fields:
Production Deployment
Ready for production with proper security configurations and optimizations using Server Actions.
Environment Setup
- Use strong AUTH_SECRET (32+ characters)
- Configure proper SMTP settings
- Set up Cloudinary for image handling
- Use production database URLs
- Enable HTTPS in production
- Configure proper CORS settings
Performance Optimizations
- Server Actions Caching: Automatic request deduplication
- Database Connection Pooling: Efficient database connections
- Image Optimization: Cloudinary CDN integration
- Session Management: Optimized session storage
- Bundle Optimization: Tree shaking and code splitting
Monitoring and Logging
Troubleshooting
Common Issues
- Database Connection: Ensure your DATABASE_URL is correct and the database is accessible.
- Email Not Sending: Check SMTP credentials and enable “Less secure app access” for Gmail.
- OAuth Errors: Verify client IDs and secrets, and configure redirect URLs properly.
- 2FA Not Working: Ensure email service is configured and tokens aren’t expired.
- Server Actions Not Working: Ensure you have “use server” directive at the top of your action files.
Conclusion
This RBAC authentication system provides a robust, secure foundation for user management in your Next.js applications. With its modern architecture, advanced security features, and seamless integration using Server Actions, you can focus on building your application while ensuring a secure and scalable authentication solution.