Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase DatabaseURL - configuring firebase

Tags:

I'm trying to use Firebase with my react app.

I have a file with the config as follows:

import * as firebase from 'firebase';

const config = {
  apiKey: process.env.FIREBASE_API_KEY,
  authDomain: process.env.FIREBASE_AUTH_DOMAIN,
  databaseURL: process.env.FIREBASE_DB_URL,
  projectId: process.env.FIREBASE_PROJECT_ID,
  storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.FIREBASE_MESSAGE_ID,
}

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

const database = firebase.database();
const auth = firebase.auth()

export {firebase, auth, database };

When I try this, I get an error that says:

FIREBASE FATAL ERROR: Can't determine Firebase Database URL. Be sure to include databaseURL option when calling firebase.initializeApp().

I can't understand this error because I have config included in the call to initialise the app. Config includes the database URL.

How do you initialise the database?

like image 708
Mel Avatar asked Apr 19 '18 01:04

Mel


People also ask

How do I get Firebase Databaseurl?

You can find your Realtime Database URL in the Realtime Database section of the Firebase console. Depending on the location of the database, the database URL will be in one of the following forms: https:// DATABASE_NAME . firebaseio.com (for databases in us-central1 )

What is the difference between Firebase and Firebase admin?

The admin SDK runs your code with administrative permissions. This means it bypasses the security rules of your Firebase Database. It also has functionality to manage users and mint custom tokens and can be used to send FCM messages.


1 Answers

Same issue here. Context: Gatsby - gatsby-node.js

For SOME reason it dsnt like my env db url. need to hardcode just that value.

    const config = {
      apiKey: process.env.GATSBY_FIREBASE_API_KEY,
      authDomain: process.env.GATSBY_FIREBASE_AUTH_DOMAIN,
      databaseURL: "https://blabla.firebaseio.com",
      projectId: process.env.GATSBY_FIREBASE_PROJECT_ID,
      storageBucket: process.env.GATSBY_FIREBASE_STORAGE_BUCKET,
      messagingSenderId: process.env.GATSBY_FIREBASE_MESSAGING_SENDER_ID
    }

and it worked.

cya

like image 99
LittiosiN Avatar answered Sep 28 '22 18:09

LittiosiN