baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

Firebase Emulator support #203

Open jakubforman opened 2 years ago

jakubforman commented 2 years ago

Hi, I found a little problem with Firebase Emulator (Android & iOS environment).

Description of the problem:

Problem occurs only if you want to test your code on Emulator Enviroment. Example: You want to log in with phone, but Firebase Emulator supporting phone validation, but PhoneNumberProvider.swift or PhoneProviderHandler.java ignoring Emulator from AngularFire set in JS (typescript).

Hotfix:

iOS

Implement custom auth on ...Provider.swift or in Plugin.swift file Auth.auth().useEmulator(withHost:"localhost", port:9099) in signIn(call: ...) method.

Run only if app building with Debug configuration in Xcode scheme. In production version app does not run the code in #if statement.

#if DEBUG
     Auth.auth().useEmulator(withHost:"localhost", port:9099)
#endif

Android

Implement custom auth on ...ProviderHandler.java or in CapacitorFirebaseAuth.java file FirebaseAuth.getInstance().useEmulator("10.5.130.140", 9099) in signIn(call: ...) method. Adress cannot be localhost/127.0.0.1, must be machine local IP!

Second step need for work success also change file node_modules/capacitor-firebase-auth/android/build.gradle line~50 from implementation 'com.google.firebase:firebase-auth:19.3.1' to implementation 'com.google.firebase:firebase-auth:21.0.1' and then sync Gradle files. Version 19.3.1 not support tra emulator with method and need many more steps for override native function.

Run only if app building with Debug configuration in Xcode scheme. In production version app does not run the code in #if statement.

if(BuildConfig.DEBUG) {
     FirebaseAuth.getInstance().useEmulator("10.5.130.140", 9099);
}