First user is superadmin instead of admin

This commit is contained in:
Alex Holliday committed 2024-08-26 10:00:34 -07:00
1 parent ef02bd8078
commit 4c2cc6fb2c
5 files changed
+27 -17

No files matched your search

+2 -2
View File
@@ -10,7 +10,7 @@ const withAdminCheck = (WrappedComponent) => {
useEffect(() => { useEffect(() => {
networkService networkService
.doesAdminExist() .doesSuperAdminExist()
.then((response) => { .then((response) => {
if (response.data.data === true) { if (response.data.data === true) {
navigate("/login"); navigate("/login");
@@ -20,7 +20,7 @@ const withAdminCheck = (WrappedComponent) => {
logger.error(error); logger.error(error);
}); });
}, [navigate]); }, [navigate]);
return <WrappedComponent {...props} isAdmin={true} />; return <WrappedComponent {...props} isSuperAdmin={true} />;
}; };
const wrappedComponentName = const wrappedComponentName =
WrappedComponent.displayName || WrappedComponent.name || "Component"; WrappedComponent.displayName || WrappedComponent.name || "Component";
+1 -1
View File
@@ -301,7 +301,7 @@ const Login = () => {
return; return;
} }
networkService networkService
.doesAdminExist() .doesSuperAdminExist()
.then((response) => { .then((response) => {
if (response.data.data === false) { if (response.data.data === false) {
navigate("/register"); navigate("/register");
+15 -8
View File
@@ -23,11 +23,11 @@ import { logger } from "../../../Utils/Logger";
* Displays the initial landing page. * Displays the initial landing page.
* *
* @param {Object} props * @param {Object} props
* @param {boolean} props.isAdmin - Whether the user is creating and admin account * @param {boolean} props.isSuperAdmin - Whether the user is creating and admin account
* @param {Function} props.onContinue - Callback function to handle "Continue with Email" button click. * @param {Function} props.onContinue - Callback function to handle "Continue with Email" button click.
* @returns {JSX.Element} * @returns {JSX.Element}
*/ */
const LandingPage = ({ isAdmin, onSignup }) => { const LandingPage = ({ isSuperAdmin, onSignup }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@@ -40,7 +40,8 @@ const LandingPage = ({ isAdmin, onSignup }) => {
<Box> <Box>
<Typography component="h1">Sign Up</Typography> <Typography component="h1">Sign Up</Typography>
<Typography> <Typography>
Create your {isAdmin ? "admin " : ""}account to get started. Create your {isSuperAdmin ? "Super admin " : ""}account to get
started.
</Typography> </Typography>
</Box> </Box>
<Box width="100%"> <Box width="100%">
@@ -93,7 +94,7 @@ const LandingPage = ({ isAdmin, onSignup }) => {
}; };
LandingPage.propTypes = { LandingPage.propTypes = {
isAdmin: PropTypes.bool, isSuperAdmin: PropTypes.bool,
onSignup: PropTypes.func, onSignup: PropTypes.func,
}; };
@@ -422,7 +423,7 @@ StepThree.propTypes = {
onBack: PropTypes.func, onBack: PropTypes.func,
}; };
const Register = ({ isAdmin }) => { const Register = ({ isSuperAdmin }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
const { token } = useParams(); const { token } = useParams();
@@ -525,7 +526,10 @@ const Register = ({ isAdmin }) => {
const handleStepThree = async (e) => { const handleStepThree = async (e) => {
e.preventDefault(); e.preventDefault();
let registerForm = { ...form, role: isAdmin ? ["admin"] : form.role }; let registerForm = {
...form,
role: isSuperAdmin ? ["superadmin"] : form.role,
};
let error = validateForm(registerForm, { let error = validateForm(registerForm, {
context: { password: form.password }, context: { password: form.password },
}); });
@@ -616,7 +620,10 @@ const Register = ({ isAdmin }) => {
}} }}
> >
{step === 0 ? ( {step === 0 ? (
<LandingPage isAdmin={isAdmin} onSignup={() => setStep(1)} /> <LandingPage
isSuperAdmin={isSuperAdmin}
onSignup={() => setStep(1)}
/>
) : step === 1 ? ( ) : step === 1 ? (
<StepOne <StepOne
form={form} form={form}
@@ -664,6 +671,6 @@ const Register = ({ isAdmin }) => {
); );
}; };
Register.propTypes = { Register.propTypes = {
isAdmin: PropTypes.bool, isSuperAdmin: PropTypes.bool,
}; };
export default Register; export default Register;
+2 -2
View File
@@ -293,8 +293,8 @@ class NetworkService {
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
* *
*/ */
async doesAdminExist() { async doesSuperAdminExist() {
return this.axiosInstance.get("/auth/users/admin"); return this.axiosInstance.get("/auth/users/superadmin");
} }
/** /**
+7 -4
View File
@@ -5,8 +5,11 @@ const joi = require("joi");
//**************************************** //****************************************
const roleValidatior = (role) => (value, helpers) => { const roleValidatior = (role) => (value, helpers) => {
if (!value.includes(role)) { const hasRole = roles.some((role) => value.includes(role));
throw new joi.ValidationError(`You do not have ${role} authorization`); if (!hasRole) {
throw new Joi.ValidationError(
`You do not have the required authorization. Required roles: ${roles.join(", ")}`
);
} }
return value; return value;
}; };
@@ -66,7 +69,7 @@ const registerValidation = joi.object({
profileImage: joi.any(), profileImage: joi.any(),
role: joi role: joi
.array() .array()
.items(joi.string().valid("admin", "user")) .items(joi.string().valid("superadmin", "admin", "user"))
.min(1) .min(1)
.required(), .required(),
}); });
@@ -123,7 +126,7 @@ const deleteUserParamValidation = joi.object({
}); });
const inviteRoleValidation = joi.object({ const inviteRoleValidation = joi.object({
roles: joi.custom(roleValidatior("admin")).required(), roles: joi.custom(roleValidatior(["admin", "superadmin"])).required(),
}); });
const inviteBodyValidation = joi.object({ const inviteBodyValidation = joi.object({