2
votes

I'm using Expo SDK for my ios app, when I try to write data in the firebase database but I'm getting the error. Error: FIREBASE FATAL ERROR: Cannot parse Firebase URL. Please use https://.firebaseio.com*

My firebase config file is

const firebaseConfig = {
  apiKey: "xxxxxx",
  authDomain: "xxxxxx.firebaseapp.com",
  databaseURL: "https://xxxxxxxxxxxxxx.europe-west1.firebasedatabase.app",
  projectId: "xxxxx",
  storageBucket: "xxxxxxx.appspot.com",
  messagingSenderId: "xxxxxxxxx",
  appId: "xxxxxxxxxx",
  measurementId: "xxxxxx"
};

my function that stores the data is


signUp = () => {
   const user = firebase.auth().currentUser;
   let userid = user.uid;

   firebase
     .database()
     .ref(`users/${userid}`)
     .set({
       firstname: this.state.firstname,
       lastname: this.state.lastname,
       password: this.state.password,
       email: this.state.email,
       dob: this.state.dob,
       postcode: this.state.postcode,
     })
     .then(() => {
       alert("user created");
     })
     .catch((err) => {
       alert("error");
     });
 };

My database rules are set to true for reading and write.

I have tried the following database URL but none of them work.

const firebaseConfig = {

  databaseURL: "https://xxxxxxxxxxxxxx.europe-west1.firebaseio.com",
 
};
const firebaseConfig = {

  databaseURL: "https://xxxxxxxxxxxxxx.firebaseio.com",
 
};

Looking for help, please

3
It'd really help to see exactly where the error message is coming from. But I'd recommend explicitly passing the URL into the database initialization with: firebase.database().ref("https://<DATABASE_NAME>.firebasedatabase.app") as a workaround either way.Frank van Puffelen
@FrankvanPuffelen I tried that, it gives me the same errorgangata arun

3 Answers

3
votes

firebaser here

Somehow Expo seems to pin you on Firebase SDK version 7.9, which was released in February 2020. This predates the addition of the firebasedatabase.app URLs, which happened in May 2020, and was released in version 7.15.4 of the JavaScript SDK, as far as I can see.

The problem disappears when I upgrade the SDK dependency to 7.14.5, despite the Expo Snack editor showing an error when I do:

{
  "dependencies": {
    "react-native-paper": "3.6.0",
    "expo-constants": "~9.3.1",
    "firebase": "7.14.5"
  }
}

My recommendation would be to upgrade to the latest versions of the SDK, as shown in the configuration snippets in the Firebase console and documentation.

3
votes

Upgrading Firebase package to the latest version fixes the issue

"firebase": "^8.2.3"
1
votes

Did you initialize the config? Something like this.

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/database';
import 'firebase/auth';
import 'firebase/storage';
import 'firebase/functions';

interface ConfigProps {
    apiKey: string;
    authDomain: string;
    databaseURL: string;
    projectId: string;
    storageBucket: string;
    messagingSenderId: string;
    appId: string;
}

const config: ConfigProps = {
    apiKey: '******************',
    authDomain: '******************',
    databaseURL: '******************',
    projectId: '******************,
    storageBucket: '******************',
    messagingSenderId: '******************',
    appId: '******************',
};

firebase.initializeApp(config);
firebase.firestore();

export default firebase;