【问题标题】:Ionic/Angular + Firebase with emulator on Android device = auth/network-request-failedIonic/Angular + Firebase 与 Android 设备上的模拟器 = auth/network-request-failed
【发布时间】:2021-07-15 21:17:32
【问题描述】:

我必须改进现有的 Ionic 应用程序,使用 firebase 作为用户登录的身份验证方法。 出于我的目的,我无法在生产 firebase 应用程序中触摸现有的先前注册用户列表,我必须使用 firebase 模拟器在本地创建新列表。 添加并设置本地身份验证和数据库模拟器扩展后,我已将其添加到app.module.ts

if (window.location.hostname === 'localhost') {
  firebase.auth().useEmulator('http://localhost:9099');
}

在继续添加新的 UI 和逻辑功能,使用网络浏览器测试我的工作后,我切换到 Android 平台。运行应用并执行后

firebase.auth().signInWithEmailAndPassword(email, password);

我收到以下错误:

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

它在浏览器中运行良好,但在真实设备上却不行。

【问题讨论】:

    标签: android angular ionic-framework firebase-authentication firebase-tools


    【解决方案1】:

    而在 Android 设备上

    window.location.hostname === 'localhost

    这将被执行

    firebase.auth().useEmulator('http://localhost:9099');

    所以 Firebase 在 9099 端口的设备上搜索身份验证服务,不存在,并产生这样的错误。

    要解决这个问题,只需在终端中运行

    adb reverse tcp:9099 tcp:9099
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      • 2016-12-16
      • 2017-08-31
      • 2018-04-12
      • 2020-08-02
      • 1970-01-01
      • 2012-04-20
      相关资源
      最近更新 更多