From c7b1c547b0aacda1b64fb7ee735ac640e8f12bf8 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 24 Aug 2023 19:42:36 +0100 Subject: [PATCH] Introduce endpoint for auth check Signed-off-by: Fred Boniface --- src/controllers/registration.controllers.js | 11 ++++++++++- src/routes/user2.routes.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/controllers/registration.controllers.js b/src/controllers/registration.controllers.js index 37b4d20..4cc4ba0 100644 --- a/src/controllers/registration.controllers.js +++ b/src/controllers/registration.controllers.js @@ -35,8 +35,17 @@ async function getUser(req, res, next) { } } +async function checkAuth(req,res,next) { + if (! req.isAuthed) { + res.status(401).body("Not Authorised") + } else { + res.status(200).body("Authorised Successfully") +} +next()} + module.exports = { register, request, - getUser + getUser, + checkAuth }; \ No newline at end of file diff --git a/src/routes/user2.routes.js b/src/routes/user2.routes.js index 0b29e00..03a5588 100644 --- a/src/routes/user2.routes.js +++ b/src/routes/user2.routes.js @@ -4,6 +4,7 @@ const regCtr = require('../controllers/registration.controllers'); // User router.get('/:uuid', regCtr.getUser); +router.get('/checkAuth', regCtr.checkAuth); // Not Implemented router.delete('/:uuid', regCtr.deleteUser); router.post('/request', regCtr.request); router.post('/register', regCtr.register);