I’m using the Firebase Authentication Emulator with Flutter on Android, and I’m encountering an issue during signInWithEmailAndPassword
. The logs show the following message:
FirebaseAuth: Logging in as jon.doe@example.com with empty reCAPTCHA token
After a delay, the process eventually throws an exception:
Unexpected FirebaseAuthException: [firebase_auth/network-request-failed] A network error (such as timeout, interrupted connection or unreachable host) has occurred.
In my main.dart
, I initialize Firebase and configure the Authentication Emulator when useEmulator
is set to true
:
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
if (useEmulator) {
String host = Platform.isAndroid ? '10.0.2.2' : 'localhost';
await FirebaseAuth.instance.useAuthEmulator(host, 9099);
}
I then attempt to sign in using the following code:
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: email,
password: password,
);
} on FirebaseAuthException catch (e) {
if (e.code == 'invalid-credential') {
if (kDebugMode) {
print('Invalid credentials');
}
} else {
if (kDebugMode) {
print('Unexpected FirebaseAuthException: $e');
}
}
} catch (e) {
if (kDebugMode) {
print('Unexpected Exception: $e');
}
}
Flutter Doctor:
- Flutter version: 3.27.1 (stable)
- Android toolchain: Android SDK version 35.0.0
- macOS version: 15.2 (24C101 darwin-arm64)
- Xcode version: 16.0
- Android Studio version: 2024.2
- VS Code version: 1.96.4
- Connected devices: 5
- Network resources: Accessible
What I’ve Tried:
- Verified the Authentication Emulator is running and accessible at
http://localhost:9099
.
- Ensured that
10.0.2.2
is used for the emulator host on Android.
- Confirmed that cleartext traffic is enabled in
AndroidManifest.xml
.
- Tested the same code against production Firebase Auth, which works without issues.
I’m wondering why the emulator logs an empty reCAPTCHA token and why a network error occurs. Is there something specific about the emulator’s setup or configuration that might be causing this issue?