我已经设置了一个firebase简单登录,它的所有工作都在我的角度项目中。但是对于soem的原因,当我调用我设置的包含login和createUser方法的函数时,它们被调用两次?
控制器设置如下:
angular.module('webApp')
.controller('AccountCtrl', function($scope, $window, $timeout) {
var ref = new Firebase('https://sizzling-fire-4246.firebaseio.com/');
并且这两种方法都直接放在我们的函数中,直接来自他们网站上的firebase示例
当我按下注册时,它将创建用户并对其进行身份验证,然后它将再次运行并告诉我已收到电子邮件。
我已经检查过是否有超时但仍然会发生。
$scope.login = function(){
$scope.loginErrors = [];
$scope.loginSuccess = '';
var user = $scope.loginUser;
if(user.email === ''){
$scope.loginErrors.push('Please enter your email');
}
else if(user.password === ''){
$scope.loginErrors.push('Please enter your password');
}
else if(user.email === 'Admin'){
$window.location.href = '/#/admin';
} else {
ref.authWithPassword({
email : user.email,
password : user.password
}, function(error, authData) {
if (error) {
switch(error.code) {
case 'INVALID_EMAIL':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter a valid email address'; }, 500);
break;
case 'INVALID_USER':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter a valid user address'; }, 500);
break;
case 'INVALID_PASSWORD':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter the correct password'; }, 500);
break;
default:
console.log('error', error);
}
} else {
console.log('Authenticated successfully with payload:', authData);
$window.location.href = '/#/dashboard';
}
});
}
任何帮助将不胜感激
答案 0 :(得分:0)
我在开发时遇到了类似的问题,我有两个浏览器标签运行浏览器同步。关闭一个,问题就消失了。