feat: implement admin dashboard with password-protected event listing
This commit is contained in:
@@ -108,4 +108,22 @@ router.get('/events/:id/analytics', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Admin: Get All Events (password protected)
|
||||
router.get('/admin/events', (req, res) => {
|
||||
const password = req.headers['x-admin-password'];
|
||||
const adminPassword = process.env.ADMIN_PASSWORD || '123456';
|
||||
|
||||
if (password !== adminPassword) {
|
||||
return res.status(401).json({ error: 'Unauthorized' });
|
||||
}
|
||||
|
||||
try {
|
||||
const events = db.prepare('SELECT id, name, description, start_date, end_date, created_at FROM events ORDER BY created_at DESC').all();
|
||||
res.json({ events });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'Failed to retrieve events' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user