Initiële commit: VibeFinance 3-container opzet
Basislijn van de bestaande applicatie (Vite/React frontend, Express backend, PostgreSQL) zoals die in de index stond, plus dev-, release- en documentatiescripts. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import { config } from "../config/index.js";
|
||||
|
||||
export function authenticate(req, res, next) {
|
||||
const header = req.headers.authorization;
|
||||
if (!header?.startsWith("Bearer ")) {
|
||||
return res.status(401).json({ error: "Niet ingelogd." });
|
||||
}
|
||||
try {
|
||||
req.user = jwt.verify(header.slice(7), config.JWT_SECRET);
|
||||
next();
|
||||
} catch {
|
||||
res.status(401).json({ error: "Sessie verlopen. Log opnieuw in." });
|
||||
}
|
||||
}
|
||||
|
||||
export function requireAdmin(req, res, next) {
|
||||
if (req.user?.rol !== "Admin") {
|
||||
return res.status(403).json({ error: "Geen toegang." });
|
||||
}
|
||||
next();
|
||||
}
|
||||
Reference in New Issue
Block a user