简体   繁体   English

Firebase 推送到实时数据库不起作用

[英]Firebase Push to real-time database not working

I am trying to push values into the firebase realtime database in react-native .我正在尝试将值推送到 react-native 中的firebase实时数据库中。 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.尝试从起始组件App.js以及相关组件的componentDidMount()和其他相关方法推送数据,事件未触发。

Changed the configuration by linking a different project in firebase, still not working.通过在 firebase 中链接不同的项目来更改配置,仍然无法正常工作。

../config/db.js ../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应用程序.js

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

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

App's firebase database App的firebase数据库

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.默认情况下,您的数据库规则需要 Firebase 身份验证,并且仅向经过身份验证的用户授予完全读写权限。 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查看: https://firebase.google.com/docs/database/security/quickstart#sample-rules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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