Added admin role to registration

This commit is contained in:
Alex Holliday committed 2024-07-03 11:21:14 -07:00
1 parent 3a1bd48d89
commit 9a382210b6
2 files changed
+8 -3

No files matched your search

+5 -3
View File
@@ -37,6 +37,7 @@ const Register = () => {
lastname: "", lastname: "",
email: "", email: "",
password: "", password: "",
role: "",
}); });
useEffect(() => { useEffect(() => {
@@ -50,7 +51,7 @@ const Register = () => {
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
}); });
}, [navigate]); }, [form, navigate]);
useEffect(() => { useEffect(() => {
const { error } = registerValidation.validate(form, { const { error } = registerValidation.validate(form, {
@@ -76,8 +77,9 @@ const Register = () => {
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
try { try {
await registerValidation.validateAsync(form, { abortEarly: false }); const adminForm = { ...form, role: "admin" };
const action = await dispatch(register(form)); await registerValidation.validateAsync(adminForm, { abortEarly: false });
const action = await dispatch(register(adminForm));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
const token = action.payload.data; const token = action.payload.data;
+3
View File
@@ -22,6 +22,9 @@ const registerValidation = joi.object({
"string.min": "Password must be at least 8 characters", "string.min": "Password must be at least 8 characters",
"string.empty": "Password is required", "string.empty": "Password is required",
}), }),
role: joi.string().required().messages({
"string.empty": "Role is required",
}),
}); });
const loginValidation = joi.object({ const loginValidation = joi.object({