在 Javascript 中调用 .removeUser() 失败
Calling .removeUser() failed in Javascript
当我尝试在密码和电子邮件中删除用户时,它给我这个错误:
Error: Firebase.removeUser failed: First argument must contain the key "email" with type "string"
at Error (native)
at bg (https://cdn.firebase.com/js/client/2.2.4/firebase.js:134:225)
at U.Se (https://cdn.firebase.com/js/client/2.2.4/firebase.js:258:380)
at Scope.$scope.removeUser (https://preview.c9users.io/amanuel2/fourm/settingsController.js:8:24)
at fn (eval at <anonymous> (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:13036:15), <anonymous>:4:221)
at callback (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:23090:17)
at Scope.$eval (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:15719:28)
at Scope.$apply (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:15818:23)
at HTMLButtonElement.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:23095:23)
at HTMLButtonElement.jQuery.event.dispatch (https://preview.c9users.io/amanuel2/fourm/jquery.js:4435:9)
我不明白。我尝试了几种方法来解决这个问题,但没有奏效。非常感谢帮助,谢谢 Here 是我的 cloud9 文件。
这是它起作用的 js:
angular.module('LoginApp')
.controller("settingsController", ["$scope", "AuthService","$firebaseAuth",
function($scope, AuthService, $firebaseAuth) {
$scope.removeUser = function(){
var firebase = new Firebase("https://uniquecoders.firebaseio.com/");
firebase.removeUser({
email: AuthService.User.email,
password: AuthService.User.password
}, function(error) {
if (error) {
switch (error.code) {
case "INVALID_USER":
console.log("The specified user account does not exist.");
break;
case "INVALID_PASSWORD":
console.log("The specified user account password is incorrect.");
break;
default:
console.log("Error removing user:", error);
}
} else {
//Remove Data from our personal data we created
firebase.child("users").child(AuthService.User.uid).remove().then(function(){
window.location.hash = "/"
setTimeout(function(){
alert("Successfully Removed")
}, 700)
})
}
});
}
$scope.resetPassword = function(){
var firebase = new Firebase("https://uniquecoders.firebaseio.com/");
firebase.resetPassword({
email: AuthService.User.email
}, function(error) {
if (error) {
switch (error.code) {
case "INVALID_USER":
console.log("The specified user account does not exist.");
break;
default:
console.log("Error resetting password:", error);
}
} else {
console.log("Password reset email sent successfully!");
}
});
}
}]
)
我检查了您在 cloud9 中的代码,您似乎忘记在 loginController
中向 User.email 和 User.password 添加数据
firebase.child("users").child(userData.uid).once('value', function(snapshot){
AuthService.User.username = snapshot.val().username;
AuthService.User.uid = userData.uid;
});
当我尝试在密码和电子邮件中删除用户时,它给我这个错误:
Error: Firebase.removeUser failed: First argument must contain the key "email" with type "string"
at Error (native)
at bg (https://cdn.firebase.com/js/client/2.2.4/firebase.js:134:225)
at U.Se (https://cdn.firebase.com/js/client/2.2.4/firebase.js:258:380)
at Scope.$scope.removeUser (https://preview.c9users.io/amanuel2/fourm/settingsController.js:8:24)
at fn (eval at <anonymous> (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:13036:15), <anonymous>:4:221)
at callback (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:23090:17)
at Scope.$eval (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:15719:28)
at Scope.$apply (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:15818:23)
at HTMLButtonElement.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js:23095:23)
at HTMLButtonElement.jQuery.event.dispatch (https://preview.c9users.io/amanuel2/fourm/jquery.js:4435:9)
我不明白。我尝试了几种方法来解决这个问题,但没有奏效。非常感谢帮助,谢谢 Here 是我的 cloud9 文件。
这是它起作用的 js:
angular.module('LoginApp')
.controller("settingsController", ["$scope", "AuthService","$firebaseAuth",
function($scope, AuthService, $firebaseAuth) {
$scope.removeUser = function(){
var firebase = new Firebase("https://uniquecoders.firebaseio.com/");
firebase.removeUser({
email: AuthService.User.email,
password: AuthService.User.password
}, function(error) {
if (error) {
switch (error.code) {
case "INVALID_USER":
console.log("The specified user account does not exist.");
break;
case "INVALID_PASSWORD":
console.log("The specified user account password is incorrect.");
break;
default:
console.log("Error removing user:", error);
}
} else {
//Remove Data from our personal data we created
firebase.child("users").child(AuthService.User.uid).remove().then(function(){
window.location.hash = "/"
setTimeout(function(){
alert("Successfully Removed")
}, 700)
})
}
});
}
$scope.resetPassword = function(){
var firebase = new Firebase("https://uniquecoders.firebaseio.com/");
firebase.resetPassword({
email: AuthService.User.email
}, function(error) {
if (error) {
switch (error.code) {
case "INVALID_USER":
console.log("The specified user account does not exist.");
break;
default:
console.log("Error resetting password:", error);
}
} else {
console.log("Password reset email sent successfully!");
}
});
}
}]
)
我检查了您在 cloud9 中的代码,您似乎忘记在 loginController
中向 User.email 和 User.password 添加数据firebase.child("users").child(userData.uid).once('value', function(snapshot){
AuthService.User.username = snapshot.val().username;
AuthService.User.uid = userData.uid;
});