Dee S
Dee S

Reputation: 1295

React Native and Firebase 3

I am trying to integrate React Native and Firebase 3 Authentication. My code.

import { FIREBASE_CONFIG } from '../config';
import firebase from 'firebase/app';
import firebaseDatabase from 'firebase/database';
import firebaseAuth from 'firebase/auth';

firebase.initializeApp(FIREBASE_CONFIG);

export const rootRef = firebase.database();
export const authRef = firebase.auth();
the config

module.exports = {
  FIREBASE_CONFIG: {
    apiKey: "long string from firebase",
    authDomain: "xxxxx.firebaseapp.com",
    databaseURL: "https://xxxxx.firebaseio.com",
    storageBucket: "xxxxx.appspot.com"
  }
}

But... Error from adding Firebase 3 Auth to react

I'm I missing something? If I am, can you point me in the right direction config

Upvotes: 2

Views: 3008

Answers (4)

Salakar
Salakar

Reputation: 6314

Whilst the Firebase JS SDK does work on react native now, it is mainly built for the web and generally not the best solution for react-native.

The Firebase Web SDK runs entirely on react native's JS thread, therefore affecting your application frame rate (the link explains this well).

In my tests, the native firebase SDK's has been roughly 2-3 times quicker than using the web SDK.

But on top of the potential performance impacts there's a lot of features you'll be unable to use with the web SDK on android/ios devices. For example:

  • Notifications / FCM
  • Storage upload/download
  • Firebase Crash Reporting
  • Analytics
  • Use of social authentication providers

The best approach would be to run with the native android/ios firebase sdk's and have a bridge between them and your js code (i.e. a native module setup).

Thankfully you don't have to implement this yourself, there's already modules out there to do this for you:

react-native-firebase for example mirrors the the web sdk's api js side but executes on the native side using the native android & ios firebase sdk's. It's fully compatible with any existing firebase js logic that you may have already implemented and is intended as a drop in replacement for the web sdk.

(disclaimer: I am the author of react-native-firebase)

Upvotes: 0

Antoine
Antoine

Reputation: 5699

To use the Firebase JS SDK 3.1+, you might have to import the whole package:

import firebase from 'firebase'

instead of just firebase/app etc, otherwise you could get this error:

The React native compatibility library was not found.

Upvotes: 1

Benn Sandoval
Benn Sandoval

Reputation: 903

The new release of firebase Javascript SDK 3.1.0 has React Native compatibility.

https://firebase.google.com/support/release-notes/js#3.1.0

Upvotes: 1

Cheol Kang
Cheol Kang

Reputation: 89

new firebase don't support react-native. If you want to use firebase in react-native, you use firebase version 2.4.2. In version 3, firebase auth cannot be used but realTimeDatabase can be used in firebase3. If you want to use firebase3 auth, I recommend using web view, react-native-login but I think it's so not good.

Upvotes: 2

Related Questions