【发布时间】:2018-07-12 08:28:57
【问题描述】:
我正在使用带有 Postgresql 数据库的 React on Express 开发 Web 应用程序,并且正在努力让用户能够删除/更新他们的个人资料。我已经针对这些更改更新了控制器、模型和路由,但是在确定从 React 组件发送获取请求的位置时遇到了问题。每当我尝试运行删除或更新时,我都会在终端上收到以下信息:
PUT /api/auth/1 400 3.468 ms - 24
--- undefined /robots.txt
我在这里检查了其他线程,但无法找到如何确定我应该为这些函数指向哪个 URL。我认为一旦我得到它应该按预期工作。以下是我的身份验证路线和我设置的功能,如果有人能建议我如何确定指向哪个 URL,我将不胜感激。
// handle profile update/delete
authRouter.route('/dashboard')
.get(usersController.show)
.put(usersController.update)
.delete(usersController.delete)
用户更新/删除功能:
handleUpdateSubmit(e, data, id) {
e.preventDefault()
console.log('clicked')
fetch(`/api/auth/${id}`, {
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/dashboard'
})
}).catch(err => console.log(err))
}
userDelete(id) {
fetch(`/api/auth/${id}`, {
method: 'DELETE',
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/'
})
}).catch(err => console.log(err))
}
如果有任何信息有助于解决这个问题,请告诉我,我会立即提供,谢谢!
【问题讨论】:
标签: postgresql reactjs express authentication