API: Move API Key auth to middelware file

This commit is contained in:
2023-04-17 15:28:13 +02:00
parent e2f18e1df5
commit 5712ea38c1
2 changed files with 16 additions and 12 deletions

View File

@@ -0,0 +1,15 @@
const ACCESS_TOKEN = process.env.API_ACCESS_TOKEN;
function isAuthorized(req, res = null) {
const providedToken = req.headers['apikey'];
if (providedToken !== ACCESS_TOKEN) {
if (res) {
res.status(401).json({ error: 'Unauthorized' });
}
return false;
}
return true;
}
module.exports = { isAuthorized };