This guide helps you migrate from the old HTTP Basic Authentication to the new comprehensive admin login system.
- Single hardcoded admin/password using HTTP Basic Auth
- No user management
- No activity logging
- Simple password stored in environment variable
- Multiple admin accounts with email/password authentication
- JWT-based authentication with sessions
- Complete admin management (invite, remove, reset)
- Comprehensive activity logging
- Strong password requirements
- Account lockout protection
Add these new environment variables to your .env file:
# Initial admin email (defaults to admin@mobyinc.com)
INITIAL_ADMIN_EMAIL=your-admin@example.com
# JWT secret (CHANGE THIS IN PRODUCTION)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# Session secret (CHANGE THIS IN PRODUCTION)
SESSION_SECRET=your-super-secret-session-key-change-this-in-productionRemove the old EXPORT_PASSWORD variable as it's no longer used.
The system will automatically create two new collections in MongoDB:
admins- Stores admin user accountsactivitylogs- Stores all admin actions
No manual database migration is required.
On first startup after migration:
- The system will check if any admin accounts exist
- If none exist, it will create an initial admin account
- The email will be from
INITIAL_ADMIN_EMAILenv var (or admin@mobyinc.com) - A random password will be generated and:
- Sent via email if SendGrid is configured
- Displayed in the console if email fails
- Old: HTTP Basic Auth header on protected endpoints
- New: Login via
POST /auth/login, then use session cookie or JWT token
All previously protected endpoints now require admin authentication:
GET /export→ Still available but requires admin loginGET /events→ Now requires admin authentication
The following new routes are available:
/- Admin dashboard (replaces simple "hello!" message)/admin/login- Login page/admin/manage- Admin management interface/admin/activity- Activity logs viewer
If you have clients accessing the API:
// Basic auth header
headers: {
'Authorization': 'Basic ' + btoa('admin:password123!')
}// 1. Login first
const loginResponse = await fetch('/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: 'admin@example.com',
password: 'your-password'
})
});
const { token } = await loginResponse.json();
// 2. Use token for subsequent requests
headers: {
'Authorization': 'Bearer ' + token
}The new system includes:
- Password hashing with bcrypt
- Account lockout after 3 failed attempts
- Session management with MongoDB store
- Activity logging for audit trails
- Strong password requirements:
- At least 8 characters
- Must include uppercase, lowercase, number, and special character
If you need to rollback:
- Restore the old
server.tsfile - Re-add the
EXPORT_PASSWORDenvironment variable - Remove the
adminsandactivitylogscollections from MongoDB - Reinstall old dependencies:
npm install express-basic-auth
If you encounter issues during migration:
- Check the server logs for any error messages
- Ensure all new environment variables are set
- Verify MongoDB connection is working
- Check that SendGrid is configured if you want email notifications