25 lines
719 B
JavaScript
25 lines
719 B
JavaScript
export const apiKeyMiddleware = async (req, res, next) => {
|
|
const authHeader = req.header('Authorization');
|
|
if (!authHeader) {
|
|
return res.status(403).json({
|
|
message: 'Forbidden: No API Key provided',
|
|
status: false
|
|
});
|
|
}
|
|
try {
|
|
if (authHeader !== "9IgFg8cnUS4XJE7Q91A0XjrWnjbnBhdk98jcI6fV1n6NAEYz31SHicge8Vkq0bCGvfKsjylb19ouri6FFUeNC1PgPvwrNCC3G5jcz4PLInlFanzf47hCsBJw4IXuhNHC"){
|
|
return res.status(403).json({
|
|
message: 'Forbidden: Invalid API Key',
|
|
status: false
|
|
});
|
|
}
|
|
next();
|
|
} catch (err) {
|
|
console.error('Erreur interne :', err);
|
|
return res.status(500).json({
|
|
message: 'Erreur interne du serveur.',
|
|
status: false
|
|
});
|
|
}
|
|
};
|