Adjust middlewares

This commit is contained in:
Fred Boniface 2023-04-07 18:06:47 +01:00
parent 5af6122646
commit 3288ddf206
2 changed files with 4 additions and 3 deletions

View File

@ -2,11 +2,11 @@ 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`, "INFO")
log.out(`authMiddlewares: Checking authentication`, "dbug")
try {
var uuid = req.headers.uuid
} catch(err) {
log.out(`authMiddlewares: No authentication attempted`, "info")
log.out(`authMiddlewares: No authentication attempted`, "dbug")
err.status = 401
return next(err)
}
@ -18,7 +18,7 @@ module.exports = async function authCheck(req, res, next) {
log.out(`authMiddlewares: Authentication attempted with incorrect key`, "warn")
return next(err)
} else {
log.out(`authMiddlewares: User authenticated`, "info")
log.out(`authMiddlewares: User authenticated`, "dbug")
return next()
}
} catch(err) {

View File

@ -2,6 +2,7 @@ const log = require('../utils/log.utils')
module.exports = async function requireJson(req, res, next) {
if (req.headers['content-type'] !== 'application/json') {
log.out(`requireJson.middlewares: Bad Request: Not in JSON format`)
res.status(400).send({status: 400, message: "Server requires JSON"})
} else {
next()