【发布时间】:2016-03-15 09:20:44
【问题描述】:
我正在尝试使用 angularfire (firebase) 使用密码实现身份验证。 javascript 是用coffeescript (!) 实现的。 创建用户,所有其他 firebase 功能似乎都可以正常工作。
但是,当尝试使用 $authWithPassword 登录用户时,它总是返回“指定密码不正确”的错误。不管密码是什么。
实现方式: 在咖啡脚本中:
$scope.loginUser = ()->
console.log("logging in! "+ $scope.loginEmail + " "+$scope.loginPassword)
$scope.auth.$authWithPassword({"email": $scope.loginEmail, "password": $scope.loginPassword})
.then (authData)->
$scope.authData = authData
console.log(authData)
$mdToast.showSimple("welcome!")
return
.catch (error)->
console.log(error)
$mdToast.showSimple("there was a problem")
return
return
..它总是返回“有问题......控制台说问题是密码” 什么地方出了错? (我仔细检查了 - 这不是密码。)
翻译成javascript:
$scope.loginUser = function() {
console.log("logging in! " + $scope.loginEmail + " " + $scope.loginPassword);
$scope.auth.$authWithPassword({
"email": $scope.loginEmail,
"password": $scope.loginPassword
}).then(function(authData) {
$scope.authData = authData;
console.log(authData);
$mdToast.showSimple("welcome!");
})["catch"](function(error) {
console.log(error);
$mdToast.showSimple("there was a problem");
});
};
--- 编辑 --- 使用的 html 标记:
<md-card-content>
<div>
<md-input-container>
<input placeholder="email" type="email" ng-model="loginEmail">
</md-input-container>
<md-input-container>
<input placeholder="password" type="password" ng-model="loginPassword">
</md-input-container>
</div>
<div><span></span>
<md-button ng-click="loginUser()" class="md-primary">
<md-icon>person</md-icon><span style="font-size:16px">connect</span>
</md-button>
</div>
</md-card-content>
我想提一下,即使将用户名和密码硬编码到 javascript 中,它仍然无法登录。所以它在 html 部分似乎不是问题。此外, loginUser() 函数确实会触发,因为我确实在控制台中收到了错误消息。
【问题讨论】:
-
你在哪里把 authData 给 ".then(function(authData))?我的意思是你从来没有给函数这个值,或者我没有看到它,所以当它尝试设置 $scope 时.authData = authData;
-
在这段代码上方的主控制器中,我有... ref = new Firebase('xxxxxxxx.firebaseio.com') $scope.auth = $firebaseAuth(ref) $scope.authData = $scope.auth. $getAuth()
-
但是当您调用“.then(function(authData))”时,您正在重命名 $scope.authData = authData;这个 authData 是 null 还是当你把它交给函数?
-
我不明白这个问题。 ".then" 函数是 $authWithPassword API 的一部分,如 angularfire 文档firebase.com/docs/web/libraries/angular/… 中所述
-
这对您有什么帮助吗? console.log(authData);
标签: angularjs coffeescript firebase angularfire firebase-authentication