I am currently working on connecting the front-end sign-in page to the backend MongoDB. However, I am encountering an error which is mentioned below. This piece of code retrieves data from the front end and sends it to the backend for registration.
name: "",
email: "",
});
let name, value;
const handleInputs = (e) => {
console.log(e);
name = e.target.name;
value = e.target.value;
setuser({ ...user, [name]: value });
};
const PostData = async (e) => {
e.preventDefault();
// http://localhost:3002/register
const [name, email] = user;
console.log(name);
console.log(email);
const res = await fetch("/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name,
email,
}),
});
const data = await res.json();
console.log(name);
console.log(email);
if (data.status === 422 || !data) {
window.alert("Invalid Registration");
} else {
window.alert("Registration Successful");
}
};
Error messages:
Uncaught (in promise) TypeError: user is not iterable at PostData (App.js:30:1) at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1) at invokeGuardedCallback (react-dom.development.js:4277:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1) at executeDispatch (react-dom.development.js:9041:1) at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
at processDispatchQueue (react-dom.development.js:9086:1) at dispatchEventsForPlugins (react-dom.development.js:9097:1) at react-dom.development.js:9288:1