From 45183f619ec7e9fafa8ce9daa352b234facc3cc9 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 30 Aug 2023 21:34:06 +0100 Subject: [PATCH] Response adjustments Signed-off-by: Fred Boniface --- src/controllers/ldb.controllers.js | 2 +- src/middlewares/auth.middlewares.js | 3 ++- src/services/dbAccess.services.js | 2 ++ src/utils/auth.utils.ts | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controllers/ldb.controllers.js b/src/controllers/ldb.controllers.js index b67686f..bbafed3 100644 --- a/src/controllers/ldb.controllers.js +++ b/src/controllers/ldb.controllers.js @@ -52,7 +52,7 @@ async function getStation(req, res, next) { if (!req.isAuthed) { const err = new Error("Unauthorized"); err.status = 401; - throw err; + return next(err); } res.json(await ldb.get(id, true)); } else { diff --git a/src/middlewares/auth.middlewares.js b/src/middlewares/auth.middlewares.js index dd17029..03ebc30 100644 --- a/src/middlewares/auth.middlewares.js +++ b/src/middlewares/auth.middlewares.js @@ -6,7 +6,7 @@ module.exports = async function authCheck(req, res, next) { try { var uuid = req.headers.uuid; } catch (err) { - log.out("authMiddlewares: User !isAuthed", "dbug"); + log.out("authMiddlewares: UNABLE TO READ HEADER 'UUID' - User !isAuthed", "warn"); req.isAuthed = false; return next(); } @@ -21,6 +21,7 @@ module.exports = async function authCheck(req, res, next) { } return next(); } catch (err) { + log.out("authMiddlewares: Unable to check auth, default to !isAuthed", "warn") req.isAuthed = false; return next(); } diff --git a/src/services/dbAccess.services.js b/src/services/dbAccess.services.js index 76c4467..4e42ba4 100644 --- a/src/services/dbAccess.services.js +++ b/src/services/dbAccess.services.js @@ -23,6 +23,8 @@ async function query(collection, query, returnId = false) { } log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, "info"); increment(collection); + log.out('dbAccess.query: Query response:') + console.log(await qcursor.toArray()) return await qcursor.toArray(); } diff --git a/src/utils/auth.utils.ts b/src/utils/auth.utils.ts index 14191c8..045c1a0 100644 --- a/src/utils/auth.utils.ts +++ b/src/utils/auth.utils.ts @@ -6,9 +6,9 @@ const fs = require("fs/promises"); import { minifyMail } from "./minify.utils"; // Checks users registration key against issued keys -async function isAuthed(uuid: string) { +async function isAuthed(uuid: string): Promise { // Needs testing - const q = { uuid: uuid }; + const q = { /*uuid: uuid*/ }; const res = await db.query("users", q); logs.out( "authUtils.checkUser: DB Query answer: " + JSON.stringify(res[0]),