【问题标题】:Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred错误:发生网络错误(如超时、连接中断或主机无法访问)
【发布时间】:2021-08-28 12:42:17
【问题描述】:

我正在使用 expo 管理的工作流程,当我尝试使用 Firebase 模拟器套件时,我总是收到此 Firebase 错误。我尝试了几件事,但我无法将我的项目(我使用 Android 模拟器)连接到模拟器套件。

这是我的 firebase 实例;

    import firebase from "firebase/app";
    import "firebase/firestore";
    import "firebase/auth";
    
    const firebaseConfig = {
      apiKey: "",
      authDomain: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
      appId: "",
      measurementId: "",
    };
    
    !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
    
    export const db = firebase.firestore();
    export const auth = firebase.auth();
    
    if (__DEV__) {
      db.settings({
        host: "localhost",
        ssl: false,
      });
      auth.useEmulator("http://localhost:9099");
    }
    
    export default firebase;

这是认证部分

        import { auth, db } from "./firebase";
    
    const regUsers = async (userCred) => {
      try {
        const user = await auth.createUserWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
    
        if (user) {
          const currentUser = auth.currentUser.uid;
          try {
            await db.collection("users").doc(currentUser).set({
              name: userCred.name,
              email: userCred.email,
              matricNumber: userCred.matricNumber,
              dateCreated: new Date(),
            });
          } catch (error) {
            console.log(
              "Something went wrong while saving user credentials",
              error
            );
          }
          return user;
        }
      } catch (error) {
        console.log("Something went wrong while registering user", error);
      }
    };
    
    const loginUser = async (userCred) => {
      try {
        const result = await auth.signInWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
        if (result) {
          const currentUser = auth.currentUser.uid;
          return currentUser;
        }
      } catch (error) {
        console.log("Something went wrong while login user", error);
      }
    };
    
    export default {
      regUsers,
      loginUser,
    };

每当我尝试登录或注册用户时,我都会收到该错误。请问有谁知道我还能尝试什么。仅当我尝试连接到模拟器时才会出现该错误,并且我所在的地方互联网连接很糟糕。 我还在我的 Firestore 调试日志中注意到了这个警告。 “io.gapi.emulators.netty.HttpVersionRoutingHandler 通道读取 信息:检测到非 HTTP/2 连接。

【问题讨论】:

标签: google-cloud-firestore firebase-authentication expo react-native-firebase firebase-tools


【解决方案1】:

显然,当您使用模拟器时,您应该将 localhost 替换为 10.0.2.2:8080,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 2020-04-13
    • 2017-02-24
    • 2021-01-03
    • 2020-01-14
    • 1970-01-01
    • 2018-01-26
    • 2019-10-04
    • 2019-07-25
    • 1970-01-01
    相关资源
    最近更新 更多