From 9fe75c92dd466ff6c3b04a78bb7e8721f25e4986 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 9 Aug 2024 13:19:05 -0700 Subject: [PATCH] Add check for JWT on login --- Server/controllers/authController.js | 4 ++++ Server/utils/messages.js | 1 + 2 files changed, 5 insertions(+) diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index 988a74174..7597416ec 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -135,6 +135,10 @@ const loginController = async (req, res, next) => { throw new Error(errorMessages.AUTH_INCORRECT_PASSWORD); } + if (user.authToken) { + throw new Error(errorMessages.AUTH_ALREADY_LOGGED_IN); + } + // Remove password from user object. Should this be abstracted to DB layer? const userWithoutPassword = { ...user._doc }; delete userWithoutPassword.password; diff --git a/Server/utils/messages.js b/Server/utils/messages.js index d04052607..590dd4eb1 100644 --- a/Server/utils/messages.js +++ b/Server/utils/messages.js @@ -7,6 +7,7 @@ const errorMessages = { UNAUTHORIZED: "Unauthorized access", AUTH_ADMIN_EXISTS: "Admin already exists", AUTH_INVITE_NOT_FOUND: "Invite not found", + AUTH_ALREADY_LOGGED_IN: "User already logged in", //Error handling middleware UNKNOWN_SERVICE: "Unknown service",