0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

errors for access denied and authorization required

This commit is contained in:
Víctor Losada Hernández
2024-06-16 17:14:27 +02:00
parent f15c831b70
commit f07252d670
2 changed files with 45 additions and 12 deletions

View File

@@ -21,10 +21,7 @@ const mw = {
loginLimiter,
(req, res, next) => {
if (!req.get('authorization')) {
return res
.set('WWW-Authenticate', 'Basic realm="Authorization Required"')
.status(401)
.send('Authorization Required');
throw { HBErrorCode: '401', code: 401, message: 'Authorization Required' };
}
const [username, password] = Buffer.from(req.get('authorization').split(' ').pop(), 'base64')
.toString('ascii')
@@ -32,7 +29,7 @@ const mw = {
if (process.env.ADMIN_USER === username && process.env.ADMIN_PASS === password) {
return next();
}
return res.status(401).send('Access denied');
throw { HBErrorCode: '403', code: 403, message: 'Access denied' };
}
]
};