API: Move API Key auth to middelware file
This commit is contained in:
15
api/middleware/apiKeyAuth.js
Normal file
15
api/middleware/apiKeyAuth.js
Normal 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 };
|
||||
Reference in New Issue
Block a user