[英]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.