ISSUE: Layout.ejs expects 'title' parameter but admin route wasn't passing it FIX: Added title: 'Dashboard' to render context Added error.message to error output for debugging Signed-off-by: Claude (Chronicler #57) <claude@firefrostgaming.com>
39 lines
1.1 KiB
JavaScript
39 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
|
|
});
|
|
} 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;
|