mysql - DELETE 用户 Express 端可以工作,但不能使其在前端工作(使用 React)
问题描述
我在服务器端(Express)创建了我的路由用户/删除,我通过 Postman 对其进行了测试并且没有任何问题,但不知何故我无法让它在前端工作。
这是我的反应代码,我正在尝试使用 axios 创建从 express 中删除和获取路由的功能:
const handleDelete = () => {
axios
.delete("http://localhost:9090/users/delete", {})
.then(response => response.data)
.catch(error => {
throw error.response.data;
});
};
这是我使用该功能的方式:
<button type="button" onClick={handleDelete}>
Delete your account
</button>
</div>
我还是这项技术的新手,所以我不确定什么是正确的方法。
解决方案
查看评论,我相信问题可能出在isAuthenticated
您正在使用的中间件上,因为当身份验证中间件失败时,它会引发403 Forbidden
错误。您可能需要传递一些令牌,以在axios
通话中验证您的请求。
const request = await axios.delete(`http://localhost:9090/users/${userId}`,{header})
如果您可以提供有关中间件的更多信息,我将更新我的答案。
推荐阅读
- flask - (1170, u"密钥规范中使用的 BLOB/TEXT 列 'user_id' 没有密钥长度")
- xamarin.forms - Xamarin:iOS 模拟器:.net 项目不支持所选的执行模式
- java - 如何拥有动态的生产者和消费者数量?
- mysql - MySql中的清除命令
- java - 需要时一一获取集合元素
- meteor - 如何通过 Meteor DDP 登录?
- c++ - 读取混合 Unicode 字符和整数的输入
- blockchain - Hyperledger Fabric 1.2 的 ACL 实现
- java - Throwable.initCause() 并通过构造函数设置原因:为什么我们仅限于设置一次原因?
- css - 仅应用带有表情符号的字体