【发布时间】:2022-02-10 20:37:22
【问题描述】:
我有一个 axios 发布请求,当我们单击按钮时会触发该请求。但是一旦单击按钮,它就会显示此错误并重新加载页面
触发请求的函数
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,
});
}
请帮忙。提前致谢!!
【问题讨论】:
-
为什么要将数据放在标题中?
-
因为有中间件来验证与 cookie 传递的相同数据
-
你能提供一个minimal reproducible example吗?
标签: javascript reactjs axios next.js