Is it possible to integrate @react-native-firebase/app with react-firebase-hooks?

I'm trying to integrate the @react-native-firebase/app package with react-firebase-hooks in my React Native application. However, I'm facing an error "TypeError: Cannot read property 'getProvider' of undefined" when trying to use the getAuth method from the 'firebase/auth' package.

Here's the code snippet I'm using:

import firebase from '@react-native-firebase/app';
import { getAuth } from 'firebase/auth';

if (!firebase.apps.length) {
  firebase.initializeApp(credentials);
}

let app = firebase.app();
const authInstance = getAuth(app);
const [user, loading, error] = useAuthState(authInstance);

When executing the above code, I receive the mentioned error. It seems that the object returned by the initializeApp method of '@react-native-firebase/app' is different from the object expected by the 'firebase/auth' package, resulting in the error when calling getAuth.

Is there a way to properly integrate '@react-native-firebase/app' with react-firebase-hooks? How can I resolve this error and use the useAuthState hook with '@react-native-firebase/app'?

Thank you in advance for any help or guidance you can provide!

Upvotes: 0

Views: 403

Answers (1)

samthecodingman
samthecodingman

Reputation: 26171

To my understanding, the @react-native-firebase/* family are made up of pseudo-SDKs, where it forwards requests to and receives responses from the native iOS and Android SDKs under the hood and returning those to the JavaScript engine. It's not a true like-for-like replacement for the JavaScript Web SDK and thus the typings don't always line up properly.

The latest version of react-firebase-hooks (and last for a while) that supports React Native is [email protected]. As mentioned above, you may experience some type conflicts that you will need to resolve manually.

The reason support was dropped was because v9+ of the Firebase Web SDK drastically changed the API surface of the SDK which fell out of sync with the way that @react-native-firebase/* defines its pseudo-methods.

Upvotes: 2

Related Questions