我对firebase,angularJS,离子和编码特别陌生,所以这个问题可能很容易解决。
这是我在Ionic中使用Firebase身份验证的控制器:
.controller('authCtrl', function($scope, $state) {
$scope.data = {};
$scope.signupEmail = function(){
var ref = new Firebase("https://places-of-interest.firebaseio.com");
ref.createUser({
email : $scope.data.email,
password : $scope.data.password
}, function(error, userData) {
if (error) {
console.log("Error creating user:", error);
} else {
console.log("Successfully created user account with uid:", userData.uid);
$state.go('start')
}
});
};
$scope.loginEmail = function(){
var ref = new Firebase("https://places-of-interest.firebaseio.com");
ref.authWithPassword({
"email": scope.data.email,
"password": $scope.data.password
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
$state.go('dash')
}
});
使用此代码,我可以向数据库添加新用户,并且条目也可见,但是当我登录时,无论我为登录凭据提供什么输入,控制台输出都只会登录我。
提前致谢!
答案 0 :(得分:0)
尝试将ref
var更改为:
var ref = new $firebaseAuth("https://places-of-interest.firebaseio.com");
请记住在您的控制器上调用该指令,如下所示:
.controller('authCtrl', function($scope, $state, $firebaseAuth) {
...
}
如果您没有,请在index.html中添加AngularFire
<script src="https://cdn.firebase.com/libs/angularfire/2.0.1/angularfire.min.js"></script>