Firebase 自定义登录失败 (JavaScript)

Firebase custom login fails (JavaScript)

我正在尝试开始使用 firebase,现在开始使用它的安全部分。我试图让它尽可能简单,以便开始使用来自 Firebase 网站的指南和代码片段。

为了简单起见,我有一个包含密码 (id "Code") 和用户输入字段 (id "Door") 的网页。如何检查字段 "Code" 中输入的密码是否等于节点 https://mydatabase.firebaseio.com/loapp_users/BAAJ/password 中已存储的密码,BAAJ 是节点 loapp_users 中存储的用户之一的用户 ID,都有子节点 "password"?

下面的代码似乎无法解决问题。

$(document).ready(function(){  
    // Monitoring User Authentication State

    // Use the onAuth() method to listen for changes in user authentication state

    // Create a callback which logs the current auth state
    function authDataCallback(authData) {
      if (authData) {
        console.log("User " + authData.uid + " is logged in with " + authData.provider);
      } else {
        console.log("User is logged out");
      }
    }
    // Register the callback to be fired every time auth state changes
    var ref = new Firebase("https://mydatabase.firebaseio.com");
    ref.onAuth(authDataCallback);

    $("#logout").click(
        function logout() {
            ref.unauth();
            ref.offAuth(authDataCallback);
        }
    );

    // LOGIN
    // The code to authenticate a user varies by provider and transport method, but they all have similar signatures and 
    // accept a callback function. Use it to handle errors and process the results of a successful login.

    // Create a callback to handle the result of the authentication
    function authHandler(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
      } else {
        console.log("Authenticated successfully with payload:", authData);
      }
    };

    $("#login").click(
        function() {
            var usersRef = new Firebase("https://mydatabase.firebaseio.com/loapp_users");
            // Authenticate users with a custom Firebase token
            var _user = $("#Door").val();
            var _level = "docent";
            var _password = $("#Code").val();
            var userRef = usersRef.child(_user);
            // Attach an asynchronous callback to read the data at our user reference
            userRef.on("value", function(snapshot) {
                console.log(snapshot.val());
                if (snapshot.val().child("password").text() == _password) {
                    ref.authWithCustomToken("eyJ0e....etc...mlhdCI6MTQyOTM4Mzc0M30.Vn1QF7cRC6nml8HB9NAzpQXJgq5lDrAie-zIHxtOmFk", authHandler);
                    } else {
                    console.log("Gebruikersnaam en code komen niet overeen")
                    }
                }, function (errorObject) {
                  console.log("The read failed: " + errorObject.code);
                });
        }
    );
});
snapshot.val().child("password").text() 

应该改为:

snaphot.val().password

然后就可以了。