- Reorganized admin settings into tabbed interface (General, Security, Payment Methods) - Vertical tabs on desktop, horizontal scrollable on mobile - Moved Payment Methods from separate menu to Settings tab - Fixed admin profile reuse and dashboard blocking - Fixed maintenance mode guard to use AppConfig model - Added admin auto-redirect after login (admins → /admin, users → /) - Reorganized documentation into docs/ folder structure - Created comprehensive README and documentation index - Added PWA and Web Push notifications to to-do list
9.3 KiB
Maintenance Mode Implementation
✅ COMPLETE: Maintenance Mode Feature Fully Implemented
Overview
Implemented a complete maintenance mode system that allows admins to temporarily disable user access to the application while keeping admin access available. The system is controlled via a toggle in the Admin Settings page.
🎯 Features Implemented
1. Backend (API)
MaintenanceGuard (/apps/api/src/common/guards/maintenance.guard.ts)
- Global guard that checks maintenance mode status from database
- Automatically blocks all requests when maintenance mode is active
- Exceptions:
- Admin users can still access the system
- Routes decorated with
@SkipMaintenance()are exempt
- Returns 503 Service Unavailable with custom maintenance message
SkipMaintenance Decorator (/apps/api/src/common/decorators/skip-maintenance.decorator.ts)
- Decorator to mark routes that should bypass maintenance mode
- Applied to:
- Health check endpoints
- Auth endpoints (login, register, OTP, Google OAuth)
- All admin endpoints
Global Guard Registration (/apps/api/src/app.module.ts)
- MaintenanceGuard registered as APP_GUARD
- Runs on every request automatically
Protected Routes
Routes that bypass maintenance mode:
/health- Health check/health/db- Database health check/auth/login- User login/auth/register- User registration/auth/verify-otp- OTP verification/auth/google- Google OAuth/auth/google/callback- Google OAuth callback/admin/*- All admin routes (for admin users only)
2. Frontend (Web)
MaintenancePage Component (/apps/web/src/components/pages/MaintenancePage.tsx)
- Beautiful, user-friendly maintenance page
- Displays custom maintenance message from admin
- Includes refresh button to check if maintenance is over
- Responsive design with proper styling
Axios Interceptor (/apps/web/src/utils/axiosSetup.ts)
- Intercepts all API responses
- Detects 503 status with
maintenanceMode: true - Triggers maintenance page display
- Extracts custom message from response
App-Level Integration (/apps/web/src/App.tsx)
- Maintenance mode state management
- Axios interceptor setup on app initialization
- Conditional rendering of maintenance page
- Preserves theme settings during maintenance
📝 How It Works
Activation Flow:
- Admin navigates to Admin Settings page
- Admin toggles "Maintenance Mode" switch to ON
- Admin can customize the maintenance message
- Admin clicks "Save Settings"
- System updates
maintenance_modeconfig in database totrue
User Experience:
- User makes any API request (e.g., loading dashboard, creating transaction)
- MaintenanceGuard intercepts the request
- Guard checks if user is admin:
- If admin: Request proceeds normally
- If regular user: Returns 503 error with maintenance message
- Frontend axios interceptor catches 503 error
- MaintenancePage is displayed to user
- User can click "Refresh" to check if maintenance is over
Deactivation Flow:
- Admin (still has access) navigates to Admin Settings
- Admin toggles "Maintenance Mode" switch to OFF
- Admin clicks "Save Settings"
- System updates
maintenance_modeconfig tofalse - Regular users can now access the application again
🔧 Configuration
Database Config Keys:
-
maintenance_mode(system category)- Type:
boolean(stored as string "true"/"false") - Default:
false - Controls whether maintenance mode is active
- Type:
-
maintenance_message(system category)- Type:
text - Default:
"System is under maintenance. Please try again later." - Custom message displayed to users
- Type:
Admin Settings UI:
Located in: /admin/settings
Maintenance Mode Section:
- Toggle switch to enable/disable
- Text area to customize message
- Visual warning (red border) when enabled
- Save button to apply changes
📁 Files Created/Modified
Created Files:
/apps/api/src/common/guards/maintenance.guard.ts- Maintenance guard/apps/api/src/common/decorators/skip-maintenance.decorator.ts- Skip decorator/apps/web/src/components/pages/MaintenancePage.tsx- Maintenance UI/apps/web/src/utils/axiosSetup.ts- Axios interceptor
Modified Files:
/apps/api/src/app.module.ts- Registered global guard/apps/api/src/health/health.controller.ts- Added @SkipMaintenance/apps/api/src/auth/auth.controller.ts- Added @SkipMaintenance to auth routes/apps/api/src/admin/admin-config.controller.ts- Added @SkipMaintenance/apps/api/src/admin/admin-users.controller.ts- Added @SkipMaintenance/apps/api/src/admin/admin-plans.controller.ts- Added @SkipMaintenance/apps/api/src/admin/admin-payments.controller.ts- Added @SkipMaintenance/apps/api/src/admin/admin-payment-methods.controller.ts- Added @SkipMaintenance/apps/web/src/App.tsx- Added maintenance mode handling/apps/web/src/components/admin/pages/AdminSettings.tsx- Already has toggle UI/apps/web/src/components/admin/pages/AdminPaymentMethods.tsx- Fixed Indonesian text/apps/web/src/components/admin/pages/AdminSettings.tsx- Fixed Indonesian text
🧪 Testing Instructions
Test Maintenance Mode Activation:
- Login as admin
- Navigate to
/admin/settings - Enable "Maintenance Mode" toggle
- Optionally change the message
- Click "Save Settings"
- Open a new incognito window
- Try to login as regular user
- After login, you should see the maintenance page
- Try to access any route - should show maintenance page
Test Admin Access During Maintenance:
- With maintenance mode ON
- Login as admin in a new window
- Verify admin can access all admin routes
- Verify admin dashboard works normally
Test Maintenance Mode Deactivation:
- As admin, go to
/admin/settings - Disable "Maintenance Mode" toggle
- Click "Save Settings"
- In the user's incognito window, click "Refresh"
- User should now be able to access the application
Test Custom Message:
- Enable maintenance mode
- Set custom message: "We're upgrading our servers. Back in 30 minutes!"
- Save settings
- Verify users see the custom message on maintenance page
🎨 UI/UX Features
Maintenance Page Design:
- ⚠️ Yellow warning icon
- Clear "Under Maintenance" heading
- Custom message display
- Additional context text
- Refresh button with icon
- Responsive layout
- Dark mode support
- Professional appearance
Admin Settings UI:
- Clear toggle switch
- Descriptive labels
- Red warning styling when enabled
- Text area for custom message
- Save button with loading state
- Success/error toast notifications
🔒 Security Considerations
✅ Admin-only access during maintenance
- Only users with
role: 'admin'can bypass maintenance mode - Regular users are completely blocked
✅ Auth routes remain accessible
- Users can still login (but will see maintenance page after)
- Prevents lockout scenarios
✅ Health checks remain accessible
- Monitoring systems can still check app health
- Database connectivity can be verified
✅ No data loss
- Maintenance mode is non-destructive
- All user data remains intact
- Simply blocks access temporarily
📊 Status Codes
- 503 Service Unavailable - Returned when maintenance mode is active
- Response includes:
{ "statusCode": 503, "message": "System is under maintenance. Please try again later.", "maintenanceMode": true }
🚀 Future Enhancements
Potential improvements:
-
Scheduled Maintenance
- Set start/end times for automatic activation/deactivation
- Countdown timer on maintenance page
-
Partial Maintenance
- Block specific features instead of entire app
- Granular control per module
-
Notification System
- Email users before maintenance
- In-app notifications about upcoming maintenance
-
Maintenance History
- Log all maintenance periods
- Track admin who activated/deactivated
-
Status Page
- Public status page showing system health
- Historical uptime data
✅ Completion Checklist
- Backend maintenance guard implemented
- Skip maintenance decorator created
- Global guard registered
- Auth routes exempted
- Admin routes exempted
- Health check routes exempted
- Frontend maintenance page created
- Axios interceptor implemented
- App-level integration completed
- Admin settings toggle working
- Custom message support added
- All Indonesian text translated
- Documentation created
🎉 Summary
Maintenance mode is now fully functional!
Admins can:
- ✅ Toggle maintenance mode ON/OFF from Admin Settings
- ✅ Customize the maintenance message
- ✅ Continue using the admin panel during maintenance
- ✅ Monitor and manage the system
Users will:
- ✅ See a professional maintenance page when mode is active
- ✅ Receive custom messages from admins
- ✅ Be able to refresh to check if maintenance is over
- ✅ Have a smooth experience when maintenance ends
The system is production-ready and can be used for scheduled maintenance, emergency fixes, or system upgrades!