Add isAuthed to request objects

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-07-08 18:20:20 +01:00
parent 45d0e0a2c0
commit 12753d76a1

View File

@ -13,12 +13,14 @@ module.exports = async function authCheck(req, res, next) {
try { try {
var result = await utils.isAuthed(uuid) || false; var result = await utils.isAuthed(uuid) || false;
if (!result) { if (!result) {
req.isAuthed = false;
const err = new Error('Unauthorised'); const err = new Error('Unauthorised');
err.status = 401; err.status = 401;
log.out('authMiddlewares: Authentication attempted with incorrect key', log.out('authMiddlewares: Authentication attempted with incorrect key',
'warn'); 'warn');
return next(err); return next(err);
} else { } else {
req.isAuthed = true;
log.out('authMiddlewares: User authenticated', 'dbug'); log.out('authMiddlewares: User authenticated', 'dbug');
return next(); return next();
} }