Spaces:
Building
Building
; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
const authentication = (req, res, next) => { | |
const authHeader = req.headers["authorization"]; | |
if (!authHeader) { | |
return res.status(401).json({ message: "Missing authorization header" }); | |
} | |
const apiKey = authHeader.split("Bearer ").at(-1); | |
if (!apiKey) { | |
return res.status(401).json({ message: "Invalid authorization format" }); | |
} | |
if (process.env.API_KEY && apiKey === process.env.API_KEY) { | |
next(); | |
} | |
else { | |
res.status(401).json({ message: "Unauthorized" }); | |
} | |
}; | |
exports.default = authentication; | |