注册反应应用时firebase身份验证出错

时间:2017-08-06 04:21:46

标签: reactjs firebase firebase-authentication

每当我尝试在本地注册时,都会收到此错误:

val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)

import sqlContext.implicits._
val client = Seq((1, "A", 10), (2, "A", 5), (3, "B", 56)).toDF("ID", "Categ", "Amnt")

    import org.apache.spark.sql.functions._
    client.groupBy("Categ").agg(sum("Amnt").as("Sum"), count("ID").as("count")).show()


+-----+---+-----+
|Categ|Sum|count|
+-----+---+-----+
|    A| 15|    2|
|    B| 56|    1|
+-----+---+-----+

注册后,我只是将用户重定向到新页面即可。

我读到使用"auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."} 制作的服务工作者可能会遇到问题,但我不完全确定禁用它是否是一个好主意。

这就是我处理注册的方式:

create-react-app

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

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

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);
    })
}

一个更好的想法我想可能是通过从函数中删除它来启动页面加载的监听器,因为它将保持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")
        }
    });

此侦听器将使用firebase.auth方法自动检测用户是否已登录/注册到您的应用程序。

希望这有帮助。

相关问题