Commented out admin check, unsure as to whether or not more than one admin can exist

This commit is contained in:
Alex Holliday
2024-07-23 14:30:27 -07:00
parent c77414f2d7
commit 608153b461
6 changed files with 23 additions and 23 deletions

View File

@@ -185,7 +185,7 @@ const TeamPanel = () => {
"/auth/invite",
{
email: toInvite.email,
role: [toInvite.role],
role: toInvite.role,
},
{ headers: { Authorization: `Bearer ${authToken}` } }
);

View File

@@ -49,6 +49,7 @@ const Register = ({ isAdmin }) => {
token,
});
const { role, email } = res.data.data;
console.log(role);
setForm({ ...form, email, role });
} catch (error) {
console.log(error);
@@ -60,8 +61,7 @@ const Register = ({ isAdmin }) => {
const handleSubmit = async (e) => {
e.preventDefault();
const registerForm = { ...form, role: isAdmin ? ["admin"] : [] };
const registerForm = { ...form, role: isAdmin ? ["admin"] : form.role };
const { error } = credentials.validate(registerForm, {
abortEarly: false,
context: { password: form.password },

View File

@@ -59,20 +59,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;
}
// TODO Can there be more than one admin?
// // 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 {

View File

@@ -172,6 +172,7 @@ const getAllUsers = async (req, res) => {
const requestInviteToken = async (req, res) => {
try {
console.log(req.body.role);
await InviteToken.deleteMany({ email: req.body.email });
let inviteToken = new InviteToken({
email: req.body.email,
@@ -188,7 +189,7 @@ const requestInviteToken = async (req, res) => {
const getInviteToken = async (req, res) => {
try {
console.log(req.body.token);
const invite = await InviteToken.findOneAndDelete({
const invite = await InviteToken.findOne({
token: req.body.token,
});
if (invite === null) {

View File

@@ -8,7 +8,7 @@ const InviteTokenSchema = mongoose.Schema(
unique: true,
},
role: {
type: String,
type: Array,
required: true,
},
token: {

View File

@@ -68,7 +68,7 @@ const editUserBodyValidation = joi.object({
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*()])[A-Za-z0-9!@#$%^&*()]+$/
),
deleteProfileImage: joi.boolean(),
role: joi.string(),
role: joi.array(),
});
const recoveryValidation = joi.object({
@@ -107,9 +107,7 @@ const inviteBodyValidation = joi.object({
"string.empty": "Email is required",
"string.email": "Must be a valid email address",
}),
role: joi.string().required().messages({
"string.empty": "Role is required",
}),
role: joi.array().required(),
});
const inviteVerifciationBodyValidation = joi.object({