import { config } from "../../config.js";

function authMiddleware(req, res, next) {
  if (!config.webApiKey) {
    return next();
  }

  const header = req.headers.authorization || "";
  const token = header.replace("Bearer ", "");

  if (token === config.webApiKey) {
    return next();
  }

  return res.status(401).json({ error: "Unauthorized" });
}

export { authMiddleware };
