【发布时间】:2016-05-06 22:33:02
【问题描述】:
我有以下代码用于使用 Firebase 进行用户授权,但我无法理解这些代码。在代码下方,我提到了我面临的疑问。请有人澄清一下。
var ref = new Firebase("https://prj_name.firebaseio.com");
var loggedInUser = [];
$(document).ready(function() {
authData=ref.getAuth();
if(authData == null){
//TODO find an elegant way to manage authorization
// window.location = "../index.html";
}else{
ref.child("users").child(authData.uid).on("value", function(snapshot){
$( "span.user-name").html(snapshot.val().displayName);
loggedInUser.displayName = snapshot.val().displayName;
});
}
$("#cPassword").focusout(function() {
validatePassword($("#cPassword"), $("#password"));
});
$(document).on("click", ".clickable-row" ,function(){
window.document.location = $(this).data("href");
});
});
function validatePassword(password, cPassword) {
if (cPassword.val() != password.val()) {
cPassword.css('border-color', 'red');
password.css('border-color', 'red');
return false;
}
return true;
}
所有必要的库(如 firebase)都已包含在内,上面的代码运行良好,唯一担心的是我无法理解它。
我的疑惑如下:
-
authData=ref.getAuth();行有什么作用以及 authData 在执行后包含什么? - 在 else 块中,value 和 snapshot 是什么。我完全不明白这一行。
ref.child("users").child(authData.uid).on("value", function(snapshot)
有人可以澄清我的疑问吗?谢谢。
【问题讨论】:
标签: javascript firebase firebase-realtime-database firebase-authentication