Restructure backend into modular API layers with admin/organizador/invitados routes, add role-based middleware, flatten module models, and update build scripts

This commit is contained in:
mberlin
2026-03-19 09:15:22 -03:00
parent 989b19d338
commit 996c6e9241
285 changed files with 6551 additions and 2914 deletions

View File

@@ -0,0 +1,23 @@
import type { NextFunction, Request, Response } from "express";
import jwt from "jsonwebtoken";
export interface AuthenticatedRequest extends Request {
user?: { id: string; email: string; role?: string };
}
export function requireAuth(req: AuthenticatedRequest, res: Response, next: NextFunction) {
const auth = req.headers.authorization?.split(" ");
const token = auth?.[1];
if (!token) {
return res.status(401).json({ error: "Missing Authorization header" });
}
try {
const payload = jwt.verify(token, process.env.JWT_SECRET ?? "change-me") as { sub: string; email: string };
req.user = { id: payload.sub, email: payload.email };
next();
} catch (err) {
return res.status(401).json({ error: "Invalid token" });
}
}