react-native-firebase (v6): App is crashing on ios when using secondary app, works fine on Android

Viewed 456

package.json-

"@react-native-firebase/app": "8.3.1",
"@react-native-firebase/auth": "8.3.3",
"@react-native-firebase/firestore": "7.5.3",

Initialisation-

export const initGuestChatConnection = async () => {
  // DEFAULT app will always be there
  if (firebase.apps.length < 2) {
    await firebase.initializeApp(
      GUEST_CHAT_FIREBASE_CONFIG,
      GUEST_CHAT_FIREBASE_CONFIG.app_name
    );
  }
};

Wrapper method to get secondary app instance-

export const getGuestChatFirebaseInstance = () => {
  return firebase.app(GUEST_CHAT_FIREBASE_CONFIG.app_name);
};

When we try to use auth (custom signin), we get following error-

Exception '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil' was thrown while invoking addAuthStateListener on target RNFBAuthModule with params (
    "GUEST_CHAT"
)

Our signin method-

export const signInGuestChatFirebaseInstance = token => {
  return getGuestChatFirebaseInstance()
    .auth()
    .signInWithCustomToken(token);
};

We thought that problem is with authentication, so we skipped it and tried to directly access Firestore (by modifying Firestore Rules) but then we started getting following error-

Exception 'FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like to use the default FirebaseApp instance.' was thrown while invoking collectionOnSnapshot on target RNFBFirestoreCollectionModule with params (
    "GUEST_CHAT",

This is working fine on Android. These methods are working on ios as well for DEFAULT Firebase app but for some reason it's crashing for secondary app.

1 Answers

Create iOS app for the secondary project in order to make it work. Since on adding iOS app it provides GoogleService-info.plist, so extract all config related info from GoogleService-info.plist and use it to create config for initialising second app. This will make secondary app work on iOS!

Related