I have an axios post request which gets triggered when we click on button. But as soon as button is clicked it shows this error and page reloads
The function on which the request is getting triggered
const handleForm = async (e) => {
//Check username is unique
e.preventDefault();
const oldUserName = await doesUserNameExist(userName);
if (oldUserName) {
activeUser.displayName = userName;
const imgUrl = await uploadPhoto(activeUser?.displayName, profilePicture);
const userFormData = {
userName,
bio,
gender,
age,
uid: activeUser.uid,
emailAddress: activeUser.email,
accountCreatedOn: serverTimestamp(),
lastSeen: serverTimestamp(),
following: [''],
followers: [''],
role: 'user',
status: '',
photoURL: imgUrl ? imgUrl : activeUser?.photoURL,
};
// await addUser(userFormData);
const nodeData = {
id: activeUser.uid,
emailAddress: activeUser.email,
userName,
};
await axios.post('path_to_api/api/user', nodeData, {
headers: nodeData,
});
}
Please Help. Thanks in advance!!
Try this :
await axios.post('path_to_api/api/user', nodeData);