Add check for JWT on login
This commit is contained in:
1 parent
5b2a05bc79
commit
9fe75c92dd
2 files changed
+5
No files matched your search
@@ -135,6 +135,10 @@ const loginController = async (req, res, next) => {
|
|||||||
throw new Error(errorMessages.AUTH_INCORRECT_PASSWORD);
|
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?
|
// Remove password from user object. Should this be abstracted to DB layer?
|
||||||
const userWithoutPassword = { ...user._doc };
|
const userWithoutPassword = { ...user._doc };
|
||||||
delete userWithoutPassword.password;
|
delete userWithoutPassword.password;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const errorMessages = {
|
|||||||
UNAUTHORIZED: "Unauthorized access",
|
UNAUTHORIZED: "Unauthorized access",
|
||||||
AUTH_ADMIN_EXISTS: "Admin already exists",
|
AUTH_ADMIN_EXISTS: "Admin already exists",
|
||||||
AUTH_INVITE_NOT_FOUND: "Invite not found",
|
AUTH_INVITE_NOT_FOUND: "Invite not found",
|
||||||
|
AUTH_ALREADY_LOGGED_IN: "User already logged in",
|
||||||
|
|
||||||
//Error handling middleware
|
//Error handling middleware
|
||||||
UNKNOWN_SERVICE: "Unknown service",
|
UNKNOWN_SERVICE: "Unknown service",
|
||||||
|
|||||||
Reference in new issue
Block a user