Firebase Auth emulator sometimes return Auth object from real Auth in the net

Viewed 74

firebase-tools: 9.23.1

Platform: macOS Flutter Mobile application Real Android device.

While running Flutter mobile application with Firebase emulators (FireStore, Auth, Functions, Storage, Hosting), I have noticed that sometimes the emulator returns Auth data from the real Auth and not from the emulator Auth. This does not happen often. I spent so many hours trying to debug this. Unfortunately, it was not easy to reproduce.

In firebase.json I have the following config:

  "emulators": {
    "ui": {
      "enabled": true,
      "port": 4000
    },
    "functions": {
      "host": "0.0.0.0",
      "port": 5001
    },
    "hosting": {
      "host": "0.0.0.0",
      "port": 5002
    },
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    },
    "pubsub": {
      "host": "0.0.0.0",
      "port": 8085
    },
    "auth": {
      "host": "0.0.0.0",
      "port": 9099
    },
    "storage": {
      "host": "0.0.0.0",
      "port": 9199
    }
  },

In my Flutter mobile App, I have the following code to use the emulators:

Future<void> _useEmulators() async {
  final ip = "192.168.1.133";
  await FirebaseStorage.instance.useStorageEmulator(ip, 9199);
  FirebaseFirestore.instance.useFirestoreEmulator(ip, 8080, sslEnabled: false);
  FirebaseFunctions.instanceFor(region: 'us-east4')
      .useFunctionsEmulator(ip, 5001);
  await FirebaseAuth.instance.useAuthEmulator(ip, 9099);
}

void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    await _useEmulators();

    return runApp(child: const App());
}
0 Answers
Related