forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminDashboardRoutes.js
More file actions
19 lines (19 loc) 路 901 Bytes
/
Copy pathadminDashboardRoutes.js
File metadata and controls
19 lines (19 loc) 路 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const express = require('express');
const router = express.Router();
const ac = require('../controllers/adminDashboardController');
const jwt = require('jsonwebtoken');
const auth = (req, res, next) => {
const token = req.header('Authorization')?.replace('Bearer ', '');
if (!token) return res.status(401).json({ error: 'No token provided' });
try { req.user = jwt.verify(token, process.env.JWT_SECRET || 'secret'); next(); }
catch (e) { return res.status(401).json({ error: 'Invalid token' }); }
};
const admin = (req, res, next) => {
if (req.user.role !== 'admin') return res.status(403).json({ error: 'Admin required' });
next();
};
router.get('/overview', auth, admin, ac.getOverview);
router.get('/payments', auth, admin, ac.getPaymentMonitoring);
router.get('/jobs', auth, admin, ac.getJobMonitoring);
router.get('/health', auth, admin, ac.getSystemHealth);
module.exports = router;