Firebase and React Native

Thanks to your continued feedback, Firebase now has broader support for React Native with version 3.1.0 of the JavaScript SDK. And, that’s not all! This version also adds unauthenticated access from the Node.js SDK, which means you can initialize an app without a service account. What does this all mean? Let’s break it down.### React Native Support When the Firebase 3.x SDK was released at Google I/O, the authentication part of the SDK was no longer compatible with React Native. The 3.1.0 release replaces the use of browser-specific APIs that allows Firebase to once again work with React Native. In addition, it fixes longstanding issues with using Firebase in React Native, including persisting authentication state across app restarts. This means all you have to do is initialize your Firebase project just as you would in any other JavaScript app:

import ReactNative from "react-native";
import * as firebase from 'firebase';
// Initialize Firebase
const firebaseConfig = {
  apiKey: "<YOUR-API-KEY>",
  authDomain: "<YOUR-AUTH-DOMAIN>",
  databaseURL: "<YOUR-DATABASE-URL>",
  storageBucket: "<YOUR-STORAGE-BUCKET>"

With the updates in the 3.1.0 SDK, almost all of the JavaScript SDK’s functionality should now work smoothly in React Native. But there are a couple caveats:

  • “Headful” auth methods such as signInWithPopup(), signInWithRedirect(), linkWithPopup(), and linkWithRedirect() do not work in React Native (or Cordova, for that matter). You can still sign in or link with a federated provider by using signInWithCredential() with an OAuth token from your provider of choice.
  • React Native does not support the File and Blob types, so Firebase Storage uploads will not work in this environment. File downloads do work however.

Unauthenticated Access

Another feature of the 3.1.0 release is support for unauthenticated access with the Node.js SDK. Previously a service account was required to use the Node.js SDK. This required you to create a service account key in the Firebase Console, download it to your server, and authenticate by referencing the file in your code. A service account is still required to create and verify tokens, but it isn’t necessary for all Node.js use cases. With the latest SDK, we’ve relaxed this requirement, so you can initialize your app with just your database URL.

import * as firebase from 'firebase';
  databaseURL: "<YOUR-DATABASE-URL>",

Without a service account, access to the Realtime Database will be restricted just like any other unauthenticated client.### Let us know what you think Thanks to everyone for their patience and voicing their opinions in our Slack Team, on our Google Group, and across our other support channels. If you run into any issues with the new SDK, please reach out. Are you excited about React Native and Firebase? Let us k