Reputation: 153
so I have been working on this Flutter app that simply needs to log into firebase authentication with an email and a password through FirebaseAuth.instance.signInWithEmailAndPassword()
. Whenever I do, it throws this error:
Android Studio Error:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/network-request-failed] Network error (such as timeout, interrupted connection or unreachable host) has occurred.
XCode Error:
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]
Here is my Dart code for the section (not sure if more is required):
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);
}
}
}
My XCode app delegate:
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 Services info file is included in the project.
If there's anything else missing, please tell me. Thanks for all the help!
Upvotes: 2
Views: 887
Reputation: 142
I had this issue because I was running an Android app on an emulator, so I added the line of code below. and after running the app on a real device using the same code, I started having problems.
FirebaseAuth.instance.useAuthEmulator("localhost", 9099);
Remove above line if you are running app in real device
Upvotes: 2
Reputation: 1019
Please check your firebase firestore rules. Go to your firebase console -> Your project -> Firestore -> Rules and change from if false:
to if true:
.
This might be the reason firebase is refusing to connect.
Make sure your app is properly configured by following the steps here
Upvotes: 1