2017-08-06 21 views
0

每当我尝试登录本地安装,我得到这个错误:误差在注册时火力权威性的反应程序

"auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."} 

在注册时,我只是将用户重定向到一个新的页面,就是这些。

我读到它可能是服务工作人员与create-react-app作出的问题,但我不完全确定是否是一个好主意,禁用它。

这是我如何处理注册:

handleSubmit(e) { 
    e.preventDefault(); 
    firebase.auth() 
    .createUserWithEmailAndPassword(this.state.emailValue, this.state.passValue) 
    .catch((error) => { 
     console.error(error) 
    }) 
    this.handleAuthChange() 
} 

handleAuthChange() { 
    firebase.auth().onAuthStateChanged((user) => { 
     if (user) { 
      window.location = 'thank-you' 
      let email = user.email 
      console.log(email + " logged in") 
     } else { 
      window.location = "" 
      console.log("not logged in") 
     } 
    }) 
} 

我应该如何解决这个问题?

回答

2

您的handleAuthChange()函数应该在成功函数中调用后,一旦登录完成,考虑到您想在firebase.auth().createUserWithEmailAndPassword函数调用后启动firebase.auth().onAuthStateChanged听众。

var self = this; 
handleSubmit(e) { 
    e.preventDefault(); 
    firebase.auth() 
    .createUserWithEmailAndPassword(this.state.emailValue, 
this.state.passValue) 
    .then(function(userData){ 
     self.handleAuthChange(); 
    }) 
    .catch((error) => { 
    console.error(error); 
    }) 
} 

一个更好的主意,我猜可能是由因为它会保持火力AUTH的状态功能删除它开始在页面加载听者页面重载的情况下。如果一个用户登录/使用firebase.auth方法签约到您的应用程序

firebase.auth().onAuthStateChanged((user) => { 
     if (user) { 
      window.location = 'thank-you' 
      let email = user.email 
      console.log(email + " logged in") 
     } else { 
      window.location = "" 
      console.log("not logged in") 
     } 
    }); 

此侦听器将自动检测。

希望这会有所帮助。

+0

为我工作,非常感谢:) – VWang