2023-05-06 21:54:49 +01:00
|
|
|
const utils = require('../utils/auth.utils');
|
|
|
|
const log = require('../utils/log.utils');
|
|
|
|
|
|
|
|
module.exports = async function authCheck(req, res, next) {
|
|
|
|
log.out('authMiddlewares: Checking authentication', 'dbug');
|
|
|
|
try {
|
|
|
|
var uuid = req.headers.uuid;
|
|
|
|
} catch(err) {
|
|
|
|
log.out('authMiddlewares: No authentication attempted', 'dbug');
|
|
|
|
err.status = 401;
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var result = await utils.isAuthed(uuid) || false;
|
|
|
|
if (!result) {
|
|
|
|
const err = new Error('Unauthorised');
|
|
|
|
err.status = 401;
|
2023-06-07 21:53:56 +01:00
|
|
|
log.out('authMiddlewares: Authentication attempted with incorrect key',
|
|
|
|
'warn');
|
2023-05-06 21:54:49 +01:00
|
|
|
return next(err);
|
|
|
|
} else {
|
|
|
|
log.out('authMiddlewares: User authenticated', 'dbug');
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
};
|