【发布时间】:2016-07-04 14:25:40
【问题描述】:
this.verifyUserToken 块中的代码不执行。我想这与异步调用有关,因为返回的数据尚未准备好,但我似乎不知道如何去做。
this.verifyUserToken = function(){
//Check if token matches existing token and if verified is true
ref.orderByChild('token').equalTo(this.token).once('value').
then(function(dataSnapshot){
//If token matches
if(dataSnapshot.val()){
alert("Token Exists",dataSnapshot.val().token);
$scope.isVerified = "YES";
}else{
alert("Token does not exist",dataSnapshot.val());
$scope.isVerified = "NO";
}
});
}
this.registerUser = function(){
console.log("Entered registerUser()");
this.verifyUserToken();
alert("The Value of isVerified:"+ $scope.isVerified);
if($scope.isVerified == "YES"){
alert("Verifying User Token...",this.verifyUserToken());
$scope.auth.$createUser({
"email": this.email,
"password" : this.password
}).then(function(userData){
alert("Successfully created user account with uid:", userData.uid);
//redirect to /userlogin if registration is successful
//this.changeVerifiedStatus();
alert("User verifed and changed");
$location.path('/userlogin');
}).catch(function(error){
alert("Error Creating User:",error);
});
}else{
alert("Token failed verification");
}
};
【问题讨论】:
-
您需要将验证放入您的 verifyUserToken 的 then 回调中。现在它将继续 isVerified 将始终为空
-
让我知道我的答案是否适合您,或者您是否仍有任何疑问。 :)
标签: javascript angularjs firebase angularfire firebase-authentication