- Add user management system with all CRUD operations - Add promotion statistics dashboard with export - Simplify Trading & Market settings UI - Fix promotion schema (dates now optional) - Add missing API endpoints and PATCH support - Add comprehensive documentation - Fix critical bugs (deletePromotion, duplicate endpoints) All features tested and production-ready.
9.5 KiB
Admin Panel Troubleshooting Guide
This guide helps you troubleshoot common issues with the TurboTrades admin panel.
Issue 1: Cannot Access Admin Panel (Routes Not Working)
Symptoms
- Navigating to
/adminredirects to home page - Admin panel doesn't load
- Getting 403 Forbidden errors
Solutions
Step 1: Check Admin Permissions
-
Verify your user has admin access:
- Your user's
staffLevelmust be 3 or higher - Check your user in the database:
// In MongoDB db.users.findOne({ steamId: "YOUR_STEAM_ID" })
- Your user's
-
Set admin via database:
// In MongoDB db.users.updateOne( { steamId: "YOUR_STEAM_ID" }, { $set: { staffLevel: 5 } } ) -
Alternative: Use environment variable:
- Add your Steam ID to
.env:ADMIN_STEAM_IDS=76561198012345678,76561198087654321 - Restart the server after adding
- Add your Steam ID to
Step 2: Verify Backend is Running
-
Check if backend is accessible:
curl http://localhost:3000/health -
Test admin routes directly:
# This should return 401 if not logged in curl http://localhost:3000/api/admin/config -
Check server logs:
- Look for route registration messages:
✅ All routes registered
- Look for route registration messages:
Step 3: Verify Frontend Development Server
-
Ensure Vite dev server is running:
cd frontend npm run dev -
Check the proxy is working:
- Open browser DevTools (F12)
- Navigate to Network tab
- Try accessing admin panel
- Check if API calls are going to
localhost:3000
-
Verify frontend build (for production):
cd frontend npm run build
Step 4: Clear Browser Cache
- Open DevTools (F12)
- Right-click the refresh button
- Select "Empty Cache and Hard Reload"
- Or use Ctrl+Shift+Del to clear all browser data
Step 5: Check Authentication
-
Verify you're logged in:
- Open browser console (F12)
- Type:
localStorageand check for session data - Or check Application → Cookies →
connect.sid
-
Test login endpoint:
# Navigate to this in your browser http://localhost:3000/api/auth/steam -
Verify session:
curl -b cookies.txt http://localhost:3000/api/auth/me
Issue 2: Toggles Not Clear/Visible
Symptoms
- Toggle switches are hard to see
- Can't tell if toggle is ON or OFF
- Toggles don't have clear labels
Solutions
Already Fixed!
The new ToggleSwitch.vue component has been created with:
- ✅ Clear ON/OFF labels inside the toggle
- ✅ Green color when ON
- ✅ Red color when OFF
- ✅ Smooth animations
- ✅ Better accessibility
If Still Having Issues:
-
Clear build cache:
cd frontend rm -rf node_modules/.vite npm run dev -
Rebuild frontend:
cd frontend npm run build
Issue 3: Admin API Calls Failing
Symptoms
- Admin panel loads but shows errors
- API calls return 401/403
- Data doesn't load in admin panels
Solutions
Check CORS Configuration
-
Verify CORS settings in
index.js:origin: (origin, cb) => { const allowedOrigins = [ "http://localhost:5173", "http://localhost:3000", // Add your production domain ]; // ... } -
Verify credentials are sent:
- Check
frontend/src/utils/axios.js:withCredentials: true
- Check
Check Middleware
-
Verify authenticate middleware:
// In routes/admin-management.js preHandler: [authenticate, isAdmin] -
Test middleware manually:
- Add console.log to
middleware/auth.js - Check server logs when accessing admin routes
- Add console.log to
Issue 4: Admin Panel Blank/White Screen
Symptoms
- Admin panel loads but is blank
- Console shows component errors
- Components not rendering
Solutions
-
Check browser console for errors:
- Press F12 → Console tab
- Look for Vue component errors
- Look for import/module errors
-
Verify all components exist:
ls frontend/src/components/Admin*.vue ls frontend/src/components/ToggleSwitch.vue -
Check component imports:
// In AdminPage.vue import AdminUsersPanel from '@/components/AdminUsersPanel.vue' import AdminConfigPanel from '@/components/AdminConfigPanel.vue' -
Rebuild with clean slate:
cd frontend rm -rf node_modules dist .vite npm install npm run build
Issue 5: Config Not Saving
Symptoms
- Clicking "Save" doesn't work
- No success/error messages
- Changes don't persist
Solutions
-
Check SiteConfig model exists:
// Should exist: models/SiteConfig.js -
Initialize config in database:
// In MongoDB db.siteconfigs.insertOne({ maintenance: { enabled: false, message: "", allowedSteamIds: [], scheduledStart: null, scheduledEnd: null }, trading: { enabled: true, depositEnabled: true, withdrawEnabled: true, minDeposit: 0.1, minWithdraw: 0.5, withdrawFee: 0.05, maxItemsPerTrade: 50 }, market: { enabled: true, commission: 0.1, minListingPrice: 0.01, maxListingPrice: 100000, autoUpdatePrices: true, priceUpdateInterval: 3600000 }, announcements: [], promotions: [] }) -
Check network requests:
- Open DevTools → Network tab
- Click save button
- Check for POST/PATCH requests
- Look at response status and body
Quick Diagnostic Commands
Backend Health Check
# Check if server is running
curl http://localhost:3000/health
# Check authentication
curl -b cookies.txt http://localhost:3000/api/auth/me
# Check admin access (should get 401 if not logged in)
curl http://localhost:3000/api/admin/config
Database Check
// Check user permissions
db.users.find({ staffLevel: { $gte: 3 } })
// Check site config exists
db.siteconfigs.findOne()
// Manually set user as admin
db.users.updateOne(
{ steamId: "YOUR_STEAM_ID" },
{ $set: { staffLevel: 5 } }
)
Frontend Check
# Check if dependencies are installed
cd frontend && npm list vue vue-router pinia
# Rebuild everything
npm install && npm run build
# Start dev server
npm run dev
Common Error Messages
"Admin access required"
Cause: User doesn't have staffLevel >= 3
Fix: Update user's staffLevel in database or add to ADMIN_STEAM_IDS
"Authentication required"
Cause: Not logged in or session expired
Fix: Log in via Steam OAuth, check cookies
"Network error"
Cause: Backend not running or CORS issue
Fix: Start backend, check CORS configuration
"Failed to fetch"
Cause: API endpoint doesn't exist or wrong URL
Fix: Check route registration in index.js, verify API base URL
Testing Admin Access
Test Script
Create a test file test-admin.js:
import axios from 'axios';
const API_URL = 'http://localhost:3000';
async function testAdmin() {
try {
// Test 1: Health check
console.log('Testing health endpoint...');
const health = await axios.get(`${API_URL}/health`);
console.log('✅ Health check passed');
// Test 2: Auth check (will fail if not logged in)
console.log('\nTesting auth endpoint...');
try {
const auth = await axios.get(`${API_URL}/api/auth/me`, {
withCredentials: true
});
console.log('✅ Authenticated:', auth.data.user.username);
console.log(' Staff Level:', auth.data.user.staffLevel);
console.log(' Is Admin:', auth.data.user.staffLevel >= 3);
} catch (e) {
console.log('❌ Not authenticated');
}
// Test 3: Admin config (will fail if not admin)
console.log('\nTesting admin config endpoint...');
try {
const config = await axios.get(`${API_URL}/api/admin/config`, {
withCredentials: true
});
console.log('✅ Admin access granted');
} catch (e) {
console.log('❌ Admin access denied:', e.response?.data?.message);
}
} catch (error) {
console.error('Error:', error.message);
}
}
testAdmin();
Run with: node test-admin.js
Still Having Issues?
-
Check all environment variables:
cat .env | grep -E "(MONGO|PORT|SESSION|ADMIN)" -
Restart everything:
# Backend npm run dev # Frontend (in another terminal) cd frontend && npm run dev -
Check logs:
- Backend: Look at console output
- Frontend: Check browser console (F12)
- Network: Check DevTools Network tab
-
Verify versions:
node --version # Should be >= 18 npm --version # Should be >= 9 -
Create a minimal test:
- Create new test user with staffLevel 5
- Log in with that user
- Navigate to /admin
- Check browser console for errors
Contact/Support
If you're still experiencing issues after trying these solutions:
- Check the server logs for error messages
- Check browser console for JavaScript errors
- Verify all files mentioned in this guide exist
- Ensure MongoDB is running and accessible
- Check that all npm packages are installed
- Try accessing from a different browser
- Review the ADMIN_SYSTEM.md for implementation details
Last Updated: Based on the latest admin panel implementation
Version: 2.0 with improved toggle switches and debugging