Overview
WAHA Dashboard implements a secure authentication system using Better Auth with email/password authentication and role-based access control. New users register as guests and must be approved by administrators before gaining full access.User Roles
The system supports three distinct user roles with different permission levels:Admin
Full system access including user management, session monitoring, and campaign oversight
User
Can create and manage campaigns, schedule messages, and view their own sessions
Guest
Limited access - awaiting admin approval to become a User
Role Definitions
prisma/schema.prisma:13
GUEST role and require admin approval:
src/server/auth.ts:21
Sign Up Flow
User Registration
New users register with their name, email, and password. The account is created with the
GUEST role.Admin Notification
The system sends dual-channel notifications to admins:
- WhatsApp message (primary)
- Email notification (fallback)
Admin Approval
Admins review pending registrations in the admin dashboard and approve or reject access.
Registration Notifications
When a new user registers, administrators are automatically notified:src/server/mailgun.ts:496
The system attempts WhatsApp notification first, then falls back to email if WhatsApp delivery fails. This ensures admins are always notified of pending registrations.
Login Flow
Authenticated users can log in using their email and password:src/server/auth.ts:9
Password Management
Password Reset
Users can request password reset links via email:src/server/auth.ts:12
- Secure reset link (expires in 1 hour)
- Security warning about unsolicited requests
- Branded HTML email template
Password Change Notifications
When a password is successfully changed, users receive a confirmation email for security purposes:src/server/mailgun.ts:162
Session Management
Sessions are stored in MongoDB with tracking metadata:prisma/schema.prisma:133
Session Features
Session Features
- Automatic expiration tracking
- IP address and user agent logging
- Cascade deletion when user is removed
- Unique token generation
Database Configuration
Authentication uses Prisma with MongoDB:src/server/auth.ts:16
Protected Routes
The application uses tRPC procedures with role-based protection:publicProcedure- Available to all usersprotectedProcedure- Requires authenticated user (USER or ADMIN role)adminProcedure- Requires ADMIN role only
Security Best Practices
Password Requirements
Password Requirements
- Minimum 8 characters
- Maximum 100 characters
- Consider implementing complexity requirements in production
Account Protection
Account Protection
- Admin accounts cannot be deleted
- Admin access cannot be revoked
- Sessions cascade delete with user accounts
Email Security
Email Security
- Password reset links expire in 1 hour
- Users notified of password changes
- No reply-to address to prevent phishing
Next Steps
Admin Dashboard
Learn about user approval and admin features
Notifications
Explore multi-channel notification system