mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
Adds an admin/member role to WebUI auth. /api/users and /api/audit are now gated by a requireAdmin middleware; all other authenticated endpoints accept both roles. Schema migration defaults all existing users to admin to preserve access. POST /api/users defaults new users to member; first-run setup always creates an admin. Adds PATCH /api/users/:id/role with last-admin demotion and deletion guards. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 lines
355 B
TypeScript
14 lines
355 B
TypeScript
import type { Request, Response, NextFunction } from "express";
|
|
|
|
export function requireAdmin(req: Request, res: Response, next: NextFunction): void {
|
|
if (!req.user) {
|
|
res.status(401).json({ error: "unauthenticated" });
|
|
return;
|
|
}
|
|
if (req.user.role !== "admin") {
|
|
res.status(403).json({ error: "forbidden" });
|
|
return;
|
|
}
|
|
next();
|
|
}
|