首页 > 解决方案 > 我的注册详细信息未保存到我的 firebase 数据库

问题描述

我正在开发这个注册应用程序,这是我在 firebase 上的第一次尝试。

我的电子邮件地址保存在 firebase 的身份验证部分,但是在我尝试将我的应用程序连接到数据库之后,以便我可以存储更多信息,当我单击注册时出现此错误:

Error: Reference.child failed: First argument was an invalid path = "undefined". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
    at validatePathString (firebase.js:1)
    at t.child (firebase.js:1)
    at userServices.js:30
    at angular.js:14634
    at m.$eval (angular.js:15878)
    at m.$digest (angular.js:15689)
    at angular.js:15917
    at e (angular.js:5490)
    at angular.js:5762

这是我的代码:

angular.module("registrationApp")
           .factory("signupService", ["$rootScope", "$firebaseAuth", signupService]);

function signupService($rootScope, $firebaseAuth) {
    var ref = firebase.database().ref();
    var auth = $firebaseAuth();

    return {
        signup: function (user) {
            auth.$createUserWithEmailAndPassword(
                user.email,
                user.password
            ).then(function (regUser) {
                var userInfo = ref.child("Users")
                    .child(regUser.uid).set({
                        date: firebase.database.ServerValue.TIMESTAMP,
                        regUser: regUser.uid,
                        firstname: user.firstName,
                        email: user.email

                    })//userInfo
                $rootScope.message = "Hi  " + user.firstName + " " + "Thanks for Registering";
            }).catch(function (error) {
                $rootScope.message = error.message;
            })
        }
    }
}`

标签: javascriptangularjsfirebasefirebase-realtime-database

解决方案


也许为时已晚,但我遇到了同样的问题,我的解决方案是将regUser.uid更改为regUser.user.uid。所以更新后的代码是:

    var userInfo= ref.child('Users')
               .child(regUser.user.uid).set({
                date: firebase.database.ServerValue.TIMESTAMP,
                regUser: regUser.user.uid,
                firstname: user.firstname,
                lastname: user.lastname,
                email: user.email
               })//userInfo

推荐阅读