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

This commit is contained in:
Alex Holliday committed 2024-07-23 14:30:27 -07:00
1 parent c77414f2d7
commit 608153b461
6 files changed
+23 -23

No files matched your search

@@ -185,7 +185,7 @@ const TeamPanel = () => {
"/auth/invite", "/auth/invite",
{ {
email: toInvite.email, email: toInvite.email,
role: [toInvite.role], role: toInvite.role,
}, },
{ headers: { Authorization: `Bearer ${authToken}` } } { headers: { Authorization: `Bearer ${authToken}` } }
); );
+2 -2
View File
@@ -49,6 +49,7 @@ const Register = ({ isAdmin }) => {
token, token,
}); });
const { role, email } = res.data.data; const { role, email } = res.data.data;
console.log(role);
setForm({ ...form, email, role }); setForm({ ...form, email, role });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -60,8 +61,7 @@ const Register = ({ isAdmin }) => {
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
const registerForm = { ...form, role: isAdmin ? ["admin"] : form.role };
const registerForm = { ...form, role: isAdmin ? ["admin"] : [] };
const { error } = credentials.validate(registerForm, { const { error } = credentials.validate(registerForm, {
abortEarly: false, abortEarly: false,
context: { password: form.password }, context: { password: form.password },
+15 -14
View File
@@ -59,20 +59,21 @@ const registerController = async (req, res, next) => {
return; return;
} }
// Check if an admin user exists, if so, error // TODO Can there be more than one admin?
try { // // Check if an admin user exists, if so, error
const admin = await req.db.checkAdmin(req, res); // try {
console.log(admin); // const admin = await req.db.checkAdmin(req, res);
if (admin === true) { // console.log(admin);
throw new Error(errorMessages.AUTH_ADMIN_EXISTS); // if (admin === true) {
} // throw new Error(errorMessages.AUTH_ADMIN_EXISTS);
} catch (error) { // }
console.log("WEEEEEEE", error.message); // } catch (error) {
error.service = SERVICE_NAME; // console.log("WEEEEEEE", error.message);
error.status = 403; // error.service = SERVICE_NAME;
next(error); // error.status = 403;
return; // next(error);
} // return;
// }
// Create a new user // Create a new user
try { try {
+2 -1
View File
@@ -172,6 +172,7 @@ const getAllUsers = async (req, res) => {
const requestInviteToken = async (req, res) => { const requestInviteToken = async (req, res) => {
try { try {
console.log(req.body.role);
await InviteToken.deleteMany({ email: req.body.email }); await InviteToken.deleteMany({ email: req.body.email });
let inviteToken = new InviteToken({ let inviteToken = new InviteToken({
email: req.body.email, email: req.body.email,
@@ -188,7 +189,7 @@ const requestInviteToken = async (req, res) => {
const getInviteToken = async (req, res) => { const getInviteToken = async (req, res) => {
try { try {
console.log(req.body.token); console.log(req.body.token);
const invite = await InviteToken.findOneAndDelete({ const invite = await InviteToken.findOne({
token: req.body.token, token: req.body.token,
}); });
if (invite === null) { if (invite === null) {
+1 -1
View File
@@ -8,7 +8,7 @@ const InviteTokenSchema = mongoose.Schema(
unique: true, unique: true,
}, },
role: { role: {
type: String, type: Array,
required: true, required: true,
}, },
token: { token: {
+2 -4
View File
@@ -68,7 +68,7 @@ const editUserBodyValidation = joi.object({
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*()])[A-Za-z0-9!@#$%^&*()]+$/ /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*()])[A-Za-z0-9!@#$%^&*()]+$/
), ),
deleteProfileImage: joi.boolean(), deleteProfileImage: joi.boolean(),
role: joi.string(), role: joi.array(),
}); });
const recoveryValidation = joi.object({ const recoveryValidation = joi.object({
@@ -107,9 +107,7 @@ const inviteBodyValidation = joi.object({
"string.empty": "Email is required", "string.empty": "Email is required",
"string.email": "Must be a valid email address", "string.email": "Must be a valid email address",
}), }),
role: joi.string().required().messages({ role: joi.array().required(),
"string.empty": "Role is required",
}),
}); });
const inviteVerifciationBodyValidation = joi.object({ const inviteVerifciationBodyValidation = joi.object({