How Authentication Works
Authentication is implemented using:- Static Password: A single password set via environment variable
- Session Cookies: HTTP-only cookies that persist for 7 days
- Server-Side Validation: All protected routes check authentication before rendering
- Rate Limiting: Login attempts are limited to prevent brute force attacks
Setting Up Authentication
1. Configure the Password
Set theDASHBOARD_PASSWORD environment variable in your deployment:
.env file:
2. Access the Login Page
Navigate to/login to access the authentication page:
3. Enter Your Password
The login form accepts the password configured inDASHBOARD_PASSWORD. Upon successful authentication:
- A session cookie is created (
os_chatbot_dashboard_auth) - You’re redirected to the main dashboard at
/ - The cookie persists for 7 days
Security Implementation
The authentication system includes several security measures:Timing-Safe Password Comparison
Passwords are compared usingtimingSafeEqual from Node.js crypto module to prevent timing attacks:
dashboard/app/api/login/route.ts
Rate Limiting
Login attempts are rate-limited by IP address:- Window: 60 seconds (1 minute)
- Max Attempts: 10 attempts per window
- Response: 429 Too Many Requests after limit exceeded
dashboard/app/api/login/route.ts:10:
HTTP-Only Cookies
Authentication cookies are configured with secure settings:dashboard/lib/auth.ts
Protected Routes
All dashboard pages except/login require authentication. This is enforced server-side:
dashboard/app/page.tsx
dashboard/lib/auth.ts:23:
Session Management
Cookie Details
- Cookie Name:
os_chatbot_dashboard_auth - Duration: 7 days from login
- Scope: Entire dashboard domain
- Security: HTTP-only, SameSite=lax
Logging Out
To end your session, click the “Log out” button on any dashboard page. This:- Clears the authentication cookie
- Redirects you to
/login - Requires re-authentication to access protected pages
dashboard/app/api/logout/route.ts.
Production Deployment
When deploying to production:Environment Variables
Set these variables in your hosting platform (e.g., Vercel):HTTPS Requirement
In production (NODE_ENV=production), the authentication cookie has the secure flag enabled, requiring HTTPS. Always deploy the dashboard over HTTPS to ensure:
- Encrypted password transmission
- Secure cookie handling
- Protection against man-in-the-middle attacks
Troubleshooting
”Invalid password” Error
Ensure:DASHBOARD_PASSWORDis set correctly in your environment- No extra whitespace or quotes in the password value
- Environment variables are loaded properly
Rate Limit Errors
If you see “Too many login attempts”:- Wait 60 seconds before trying again
- Check that you’re using the correct password
- Contact your admin if locked out repeatedly
Cookie Not Persisting
If you’re logged out immediately:- Check browser cookie settings
- Ensure cookies are enabled for the dashboard domain
- In production, verify HTTPS is configured