简体   繁体   中英

Firebase Push to real-time database not working

I am trying to push values into the firebase realtime database in react-native . Very basic query, it's not working. Please check out the code.

Tried to push the data from the starting component App.js as well as relevant component's componentDidMount() and other relevant methods, the events are not firing.

Changed the configuration by linking a different project in firebase, still not working.

../config/db.js

import Firebase from 'firebase';

var firebaseConfig = {
    apiKey: "--",
    authDomain: "--.firebaseapp.com",
    databaseURL: "---d33c8.firebaseio.com",
    projectId: "---d33c8",
    storageBucket: "---d33c8.appspot.com",
    messagingSenderId: "--",
    appId: "--",
    measurementId: "--"
  };
let app = Firebase.initializeApp(firebaseConfig);

export const db = app.database();

App.js

 import { db } from './src/config/db';

 db.ref().child('items').push({
     title : "1",
     description: "2"
 });

App's firebase database

The data is not going through. No errors.

Make sure that the rules inside your realtime database are set to this to allow not authorized users to read and write, if you don't have it like this, you can't read/write to the database

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": true,
    ".write": true
  }
}

By default, your database rules require Firebase Authentication and grant full read and write permissions only to authenticated users. The default rules ensure your database isn't accessible by just anyone before you get a chance to configure it.

Check out: https://firebase.google.com/docs/database/security/quickstart#sample-rules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM