gpt4 book ai didi

firebase 执行方法两次

转载 作者:行者123 更新时间:2023-12-01 06:25:58 25 4
gpt4 key购买 nike

我已经设置了一个 firebase 简单登录,它在我的 angular 项目中都可以正常工作。然而,出于某种原因,当我调用我设置的包含 login 和 createUser 方法的函数时,它们会被调用两次?

Controller 设置如下:

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';

}
});
}

任何帮助,将不胜感激

最佳答案

我在开发时遇到了类似的问题,我有两个浏览器选项卡运行浏览器同步。关闭一个,问题就消失了。

关于firebase 执行方法两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28581735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com