Efie
Efie

Reputation: 1690

Error integrating firebase into react app

I'm getting this error when trying to build my react app. The only thing that has changed since the build broke is me trying to add a firebase db to the app. I'm trying to implement it in the same way that I found on a tutorial I'm using.

×
REBASE: Rebase.createClass failed. Expected an initialized firebase or firestore database object.
▶ 3 stack frames were collapsed.
./src/base.js
C:/Dev/React/my-app/src/base.js:3
  1 | import Rebase from 're-base';
  2 | 
> 3 | const base = Rebase.createClass({
  4 |   apiKey: "AIzaSyC1UGLssKKLkKvYRp02zYVpM1-D88czp7I",
  5 |   authDomain: "catch-of-the-day-ethan-fie.firebaseapp.com",
  6 |   databaseURL: "https://catch-of-the-day-ethan-fie.firebaseio.com",

Code from base.js below, personal information and API key redacted:

import Rebase from 're-base';

const base = Rebase.createClass({
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
});

export default base;

Upvotes: 2

Views: 1410

Answers (3)

Mayank Pathela
Mayank Pathela

Reputation: 648

Try this, it will work:

var Rebase = require('re-base');
var firebase = require('firebase/app');
var database = require('firebase/database');
var app = firebase.initializeApp({
  apiKey: "apiKey",
  authDomain: "projectId.firebaseapp.com",
  databaseURL: "https://databaseName.firebaseio.com",
  storageBucket: "bucket.appspot.com",
  messagingSenderId: "xxxxxxxxxxxxxx"
});
var db = firebase.database(app);
var base = Rebase.createClass(db);

Upvotes: 1

Ali Faris
Ali Faris

Reputation: 18630

here you go

import Rebase from 're-base'
import firebase from 'firebase'

const config = {
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
  messagingSenderId: "SOME_MESSAGING_SENDER_ID"
}

const app = firebase.initializeApp(config)
const base = Rebase.createClass(app.database())


export default base;

Upvotes: 3

Nah
Nah

Reputation: 1768

Please check this guidelines in order to resolve the problem.

https://coderjourney.com/tutorials/how-to-integrate-react-with-firebase/

Make sure you are using correct library version syntax as mentioned in above reference.

Upvotes: 2

Related Questions