Add check for admin acount

This commit is contained in:
Alex Holliday committed 2024-07-12 10:57:39 -07:00
1 parent 7462458eca
commit b0cbea156c
2 files changed
+16

No files matched your search

+15
View File
@@ -60,6 +60,21 @@ const registerController = async (req, res, next) => {
return;
}
// Check if an admin user exists, if so, error
try {
const admin = await req.db.checkAdmin(req, res);
console.log(admin);
if (admin === true) {
throw new Error(errorMessages.AUTH_ADMIN_EXISTS);
}
} catch (error) {
console.log("WEEEEEEE", error.message);
error.service = SERVICE_NAME;
error.status = 403;
next(error);
return;
}
// Create a new user
try {
const newUser = await req.db.insertUser(req, res);
+1
View File
@@ -4,6 +4,7 @@ const errorMessages = {
UNKNOWN_ERROR: "An unknown error occurred",
// Auth Controller
UNAUTHORIZED: "Unauthorized access",
AUTH_ADMIN_EXISTS: "Admin already exists",
//Error handling middleware
UNKNOWN_SERVICE: "Unknown service",