[英]Updating password using 'PUT' method
有人可以帮助我了解如何使用创建的查询功能来更新我的数据库中的密码吗?
这是有问题的查询功能
async function updatePassword(req, res) {
return db.none('UPDATE user_account SET password = $1 WHERE email = $2',
[req.body.password, req.body.email])
.then(function () {
res.status(200)
.json({
status: 'success',
message: 'Updated user'
});
})
.catch(error => {
console.log(error)
});
}
这是我试图用 fetch 方法做的事情
resetPassword(){
fetch('http://url/example', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: this.email,
password: this.passwordReset,
}),
})
// Converting to JSON
.then(response => response.json())
// Displaying results to console
.then(json => console.log(json));
},
没有错误“{状态:'成功',消息:'更新用户'}”
但我的数据库没有任何变化
编辑:问题解决了谢谢大家
'UPDATE user_account SET password = $1 WHERE email = $2' 你传递了 req.params 和 req.body 所以在你的情况下 req.params.email 传递了它的执行和成功,我认为这是使用两者的坏主意一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.