Implement comprehensive admin user system for Kubernetes deployment: Backend: - Add isAdmin field to User model for role-based permissions - Create adminAuth middleware to protect admin-only routes - Protect 11 routes across rewards, cache, streets, and analytics endpoints - Update setup-couchdb.js to seed default admin user at deployment Kubernetes: - Add ADMIN_EMAIL and ADMIN_PASSWORD to secrets.yaml - Add ADMIN_EMAIL to configmap.yaml for non-sensitive config - Create couchdb-init-job.yaml for automated database initialization - Update secrets.yaml.example with admin user documentation Frontend: - Create AdminRoute component for admin-only page protection - Create comprehensive AdminDashboard with 5 tabs: * Overview: Platform statistics and quick actions * Users: List, search, manage admin status, delete users * Streets: Create, edit, delete streets * Rewards: Create, edit, toggle, delete rewards * Content: Moderate posts and events - Add Admin navigation link in Navbar (visible only to admins) - Integrate admin routes in App.js Default admin user: - Email: will@wills-portal.com - Created automatically by K8s init job at deployment Routes protected: - POST/PUT/DELETE /api/rewards (catalog management) - POST /api/streets (street creation) - DELETE /api/cache (cache operations) - GET /api/analytics/* (platform statistics) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
987 B
JavaScript
46 lines
987 B
JavaScript
const express = require("express");
|
|
const auth = require("../middleware/auth");
|
|
const adminAuth = require("../middleware/adminAuth");
|
|
const { asyncHandler } = require("../middleware/errorHandler");
|
|
const { getCacheStats, clearCache } = require("../middleware/cache");
|
|
|
|
const router = express.Router();
|
|
|
|
/**
|
|
* GET /api/cache/stats
|
|
* Get cache statistics
|
|
* @access Private (authenticated users)
|
|
*/
|
|
router.get(
|
|
"/stats",
|
|
auth,
|
|
asyncHandler(async (req, res) => {
|
|
const stats = getCacheStats();
|
|
res.json({
|
|
status: "operational",
|
|
...stats,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
})
|
|
);
|
|
|
|
/**
|
|
* DELETE /api/cache
|
|
* Clear all cache
|
|
* @access Private (authenticated users - in production should be admin only)
|
|
*/
|
|
router.delete(
|
|
"/",
|
|
auth,
|
|
adminAuth,
|
|
asyncHandler(async (req, res) => {
|
|
clearCache();
|
|
res.json({
|
|
msg: "Cache cleared successfully",
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
})
|
|
);
|
|
|
|
module.exports = router;
|