gpt4 book ai didi

javascript - 从 Firebase 数据库中删除用户

转载 作者:行者123 更新时间:2023-12-02 14:25:51 25 4
gpt4 key购买 nike

我开始了解有关 Firebase 的更多信息,并尝试创建一个简单的数据库。

我按照网站上的所有步骤操作,并成功在数据库中添加了成员​​。

但是...现在,有必要了解如何删除用户。

这是我添加和删除用户的代码:

<!DOCTYPE html>
<html>
<head>


</head>
<body>
<button onclick="saveData()">Save Data</button>
<button onclick="printData()">Print Data</button>
<button onclick="printData2()">Print Data2</button>
<button onclick="remove()">Remove</button>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script>
var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog");
var usersRef = ref.child("users");
function saveData(){
usersRef.set({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
},
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
}
});
}
function printData(){

usersRef.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
function printData2(){

ref.child("users/gracehop/date_of_birth").on("value", function(snapshot) {
console.log(snapshot.val());//"December 9, 1906"
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}


function remove(){
ref.removeUser({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Grace Hopper"
}

});
}
</script>
</body>
</html>

删除用户功能问题出在哪里?

感谢您的帮助!

最佳答案

第一个removeUser未在任何地方定义。其次,我认为您在 remove() 中没有使用正确的 ref,您应该使用 usersRef

尝试使用user.remove()方法。

来自the User API引用:

Deletes and signs out the user.

Important: this is a security sensitive operation that requires the user to have recently signed in. If this requirement isn't met, ask the user to authenticate again and then call firebase.User#reauthenticate.

如果要删除某个用户对应的数据库节点,可以这样做:

usersRef.remove()
.then(function() {
console.log("Remove succeeded.")
})
.catch(function(error) {
console.log("Remove failed: " + error.message)
});

关于javascript - 从 Firebase 数据库中删除用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38248086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com