Files
firefrost-services/services/arbiter-3.0/src/routes/admin.js
Claude (Chronicler #57) ab37828693 fix: add currentPath variable for layout navigation
Layout.ejs expects currentPath to highlight active menu item

Signed-off-by: Claude (Chronicler #57) <claude@firefrostgaming.com>
2026-04-03 17:32:00 +00:00

40 lines
1.1 KiB
JavaScript

const express = require('express');
const router = express.Router();
const { getRoleMappings, saveRoleMappings } = require('../utils/roleMappings');
const isAdmin = (req, res, next) => {
if (req.isAuthenticated()) {
const admins = process.env.ADMIN_USERS.split(',');
if (admins.includes(req.user.id)) return next();
}
res.status(403).send('Forbidden: Admin access only.');
};
// TODO: Replace with full beautiful UI from live bot.js
router.get('/', isAdmin, async (req, res) => {
try {
const mappings = getRoleMappings();
res.render('admin/dashboard', {
title: 'Dashboard',
user: req.user,
csrfToken: req.csrfToken(),
mappings: mappings,
currentPath: '/dashboard'
});
} catch (error) {
console.error('Admin dashboard error:', error);
res.status(500).send('Internal Server Error: ' + error.message);
}
});
router.post('/mappings', isAdmin, express.json(), (req, res) => {
const newMappings = req.body;
if (saveRoleMappings(newMappings)) {
res.status(200).send('Mappings updated');
} else {
res.status(500).send('Failed to save mappings');
}
});
module.exports = router;