【问题标题】:Flutter network not connecting to FirebaseAuth servicesFlutter 网络未连接到 FirebaseAuth 服务
【发布时间】:2022-07-28 19:34:34
【问题描述】:

所以我一直在开发这个 Flutter 应用程序,它只需要使用电子邮件和密码通过 FirebaseAuth.instance.signInWithEmailAndPassword() 登录到 Firebase 身份验证。每当我这样做时,它都会引发此错误:

Android Studio 错误:

[VERBOSE-2:dart_vm_initializer.cc(41)] 未处理异常:[firebase_auth/network-request-failed] 发生网络错误(例如超时、连接中断或无法访问主机)。

XCode 错误:

2022-05-28 22:31:47.393894+0400 Runner[53493:5966626] [connection] nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused]

这是我的 Dart 部分代码(不确定是否需要更多):

try {
   final credential =  FirebaseAuth.instance.signInWithEmailAndPassword(
        email: emailController.text,        //emailController is a text field controller
        password: passwordController.text   //passwordController is a text field controller
      );
    } 

   on FirebaseAuthException catch (e) {
     if (e.code == 'user-not-found') {
        print('No user found for that email.');
     } else if (e.code == 'wrong-password') {
        print('Wrong password provided for that user.');
     } else if (e.code.isEmpty){
        print('worked!');
     } else{
        print(e.code);
     }
   }
 }

我的 XCode 应用委托:

import Flutter
import FirebaseCore
import Firebase
import FirebaseAuth

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    FirebaseApp.initialize()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Google 服务信息文件包含在项目中。

如果还有什么遗漏的,请告诉我。感谢大家的帮助!

【问题讨论】:

  • 你得到答案了吗?
  • 遗憾的是没有。我已经尝试了所有方法,现在我只是求助于本地服务器数据库。

标签: swift flutter firebase dart firebase-authentication


【解决方案1】:

请检查您的 Firebase Firestore 规则。转到您的 Firebase 控制台 -> 您的项目 -> Firestore -> 规则并从 if false: 更改为 if true:

这可能是 firebase 拒绝连接的原因。

按照here的步骤确保您的应用已正确配置

【讨论】:

  • 不确定这是否有用,但我什至不使用 Firestore。我只是使用 Firebase 身份验证服务。尽管如此,我已经设置了具有正确权限的 Firestore,但它仍然坏了。参考 android 项目设置,我只是使用 XCode 运行器,所以我不认为 android 文件被触及或编译。
【解决方案2】:

我遇到这个问题是因为我在模拟器上运行 Android 应用,所以我添加了下面的行。

FirebaseAuth.instance.useAuthEmulator("localhost", 9099);

如果您在真实设备上运行应用程序,请删除以上行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 2011-12-26
    • 2014-10-10
    • 2012-02-05
    相关资源
    最近更新 更多