Files
VibeFinance/backend/src/middleware/auth.js
T
Jordy HoogeveenandClaude Opus 5 e45d5b73fb 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>
2026-09-04 09:19:14 +02:00

23 lines
609 B
JavaScript

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();
}