// FILE: src/routes/auth_extras.js
// Deprecated for this project (เราใช้ Bearer + authJwt() แล้ว)
import jwt from "jsonwebtoken";
const JWT_ACCESS_SECRET = process.env.JWT_ACCESS_SECRET || "dev-access-secret";
export function requireAuth(req, res, next) {
  const token = req.cookies?.access_token;
  if (!token) return res.status(401).json({ error: "Unauthenticated" });
  try {
    const payload = jwt.verify(token, JWT_ACCESS_SECRET, {
      issuer: "dms-backend",
    });
    req.user = { user_id: payload.user_id, username: payload.username };
    return next();
  } catch {
    return res.status(401).json({ error: "INVALID_TOKEN" });
  }
}
export function requireRole(_role) {
  return (_req, res, next) => res.status(403).json({ error: "FORBIDDEN" });
}
