Simplified form control in Login and Register. Fixed registration bug. Throw better errors

This commit is contained in:
Alex Holliday committed 2024-06-12 13:30:56 -07:00
1 parent 7ce28b7042
commit 08565c9eda
6 files changed
+8 -37

No files matched your search

+2 -14
View File
@@ -45,18 +45,6 @@ const registerController = async (req, res, next) => {
return;
}
// Check if the user exists
try {
const isUser = await req.db.getUserByEmail(req, res);
if (isUser) {
throw new Error("User already exists");
}
} catch (error) {
error.service = SERVICE_NAME;
next(error);
return;
}
// Create a new user
try {
const newUser = await req.db.insertUser(req, res);
@@ -101,8 +89,8 @@ const loginController = async (req, res, next) => {
// Compare password
const match = await user.comparePassword(req.body.password);
if (!match) {
throw new Error("Password does not match!");
if (match !== true) {
throw new Error("Incorrect password");
}
// Remove password from user object. Should this be abstracted to DB layer?