在下面的登录功能中,在运行成功警报(成功通过验证)后,它也会捕获错误,同时显示成功和错误消息。为什么?
有什么建议吗?请帮忙。谢谢!
登录功能:
$scope.login = function() {
$signin_email = $scope.member.email;
$signin_password = $scope.member.password;
// sign in
Auth.$signInWithEmailAndPassword($signin_email, $signin_password)
.then(function(firebaseUser) {
authenticated = true;
alert(firebaseUser.email + " logou caralho!");
$state.go('tabsController.home');
check();
}).catch(function(error) {
authenticated = false;
alert(error.message);
//$scope.error = error;
check();
});
};
答案 0 :(得分:-2)
承诺"堕落"如果他们没有明确拒绝,可以采取进一步措施。在Promise.reject
方法中添加对catch
的调用:
Auth.$signInWithEmailAndPassword($signin_email, $signin_password)
.then(function(firebaseUser) {
authenticated = true;
alert(firebaseUser.email + " logou caralho!");
$state.go('tabsController.home');
check();
}).catch(function(error)
authenticated = false;
alert(error.message);
//$scope.error = error;
check();
return Promise.reject();
});