Firebase自定义登录失败(JavaScript)
我试着从firebase开始,现在是它的安全部分。为了入门,我正在使用Firebase网站上的指南和代码片段,尽量保持它的简单性 为了保持简单,我有一个包含密码(id“Code”)和用户输入字段(id“Door”)的网页。如何检查字段“Code”中输入的密码是否等于节点中已存储的密码,BAAJ是节点loapp_用户中存储的其中一个用户的用户ID,所有这些用户都具有子节点“密码” 下面的代码似乎不起作用Firebase自定义登录失败(JavaScript),javascript,firebase-security,Javascript,Firebase Security,我试着从firebase开始,现在是它的安全部分。为了入门,我正在使用Firebase网站上的指南和代码片段,尽量保持它的简单性 为了保持简单,我有一个包含密码(id“Code”)和用户输入字段(id“Door”)的网页。如何检查字段“Code”中输入的密码是否等于节点中已存储的密码,BAAJ是节点loapp_用户中存储的其中一个用户的用户ID,所有这些用户都具有子节点“密码” 下面的代码似乎不起作用 $(document).ready(function(){ // Monitori
$(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);
});
}
);
});
应改为:
snaphot.val().password
然后它就起作用了
snaphot.val().password