0

我将 AngularJS 与 firebase 一起用于 firebaseSimpleLogin。前一阵子有用,突然就不行了。登录部分工作正常,但新用户无法注册。

var userAuthRef = new Firebase(URL+"/userAuth");
$scope.loginObj = $firebaseSimpleLogin(userAuthRef);

$scope.userSignup = function(){
        $('.signup.small.modal').modal('hide');
        if ($scope.Password!="" && angular.equals($scope.PasswordFirst, $scope.PasswordConfirm)){
            console.log($scope.Email + $scope.PasswordConfirm);  ////the first log
            $scope.loginObj.$createUser($scope.Email,$scope.PasswordConfirm)
            .then(function(auth) {
                console.log("reached here");   ////the second log
                if (auth === null) {
                    console.log("Error creating user:", error);
                } else {
                    console.log("User created successfully");
                    $scope.loginObj.$login("password", {
                        email: $scope.Email,
                        password: $scope.PasswordConfirm
                    }).then(function(user) {
                        console.log("Logged in as: ", user.uid);
                        userRef = $firebase(new Firebase(someURL+user.uid));
                        userRef.$set({username: $scope.Username, time: Date(), reported: 0});
                        $scope.user = userRef.$asObject();
                    }, function(error) {
                        console.error("Login failed: ", error);
                    });
                }
            }), function(error){
                console.error("signup failed: ", error);
                ////Sign up failure log
            };
        }
        else{
            console.log("condition does not satisfy");
        }
    };

我很确定函数 userSignup() 被调用,因为第一个 console.log 确实打印了一些东西。然后我什至不知道 $createUser 是否被执行,因为控制台不再提供任何东西。

这些是 Firebase forge 的规则:

{
  "rules": {
    ".read": true,
    "$user": {
        ".write": true
    }
  }
}

$createUser 的用法错了吗?

4

1 回答 1

1

我认为出现这个问题是因为 FirebaseSimpleLogin 现在是标准 firebase 库的一部分。看到这里,它已被弃用:https ://www.firebase.com/docs/web/api/firebasesimplelogin/

从现在开始使用此处描述的 api: https ://www.firebase.com/docs/web/api/firebase/createUser.html

如果您仍然想要一个包含身份验证数据的对象,请使用 .getAuth(): https ://www.firebase.com/docs/web/api/firebase/getAuth.html

试试下面的代码:

var userAuthRef = new Firebase(URL);
$scope.userSignup = function() {
    if ($scope.Password != "" && angular.equals($scope.PasswordFirst, $scope.PasswordConfirm)) {
        $('.signup.small.modal').modal('hide');
        console.log($scope.Email + $scope.PasswordConfirm); ////the first log
        firebaseRef.createUser({
            email: $scope.Email,
            password: $scope.PasswordConfirm
        }, function(err) {
            console.log("reached here"); ////the second log
            if (err) {
                switch (err.code) {
                    case 'EMAIL_TAKEN':
                        console.log("Error creating user, email taken:", error);
                    case 'INVALID_EMAIL':
                        console.log("Error creating user, invalid email:", error);
                    case
                    default:
                        console.log("Error creating user:", error);
                }
            } else {
                // User account created successfully!
                console.log("User created successfully");
                dataRef.authWithPassword({
                    "email": $scope.Email,
                    "password": $scope.PasswordConfirm
                }, function(error, authData) {
                    if (error) {
                        console.log('Login Failed!', error);
                    } else {
                        console.log('Authenticated successfully with payload:', authData);
                        console.log("Logged in as: ", authData.uid);
                        var userRef = $firebase(new Firebase(someURL + authData.uid));
                        userRef.$set({
                            username: $scope.Username,
                            time: Date(),
                            reported: 0
                        });
                        $scope.user = userRef.$asObject();
                    }
                });
            }
        });
    }
}
于 2014-10-30T10:35:09.033 回答