在将Firebase集成到React Web应用程序中的同时获得“拒绝权限”

时间:2018-08-24 01:47:35

标签: javascript reactjs firebase google-cloud-firestore

我正在尝试通过react Web应用程序保存文档,但是面临以下问题。我已经阅读了Firebase规则文档。

这是代码

constructor(props)
  {
    super(props);
    var config = {
      apiKey: "<apiKey>",
      authDomain: "<authDomain>",
      databaseURL: "<databaseURL>",
      projectId: "<projectId>",
      storageBucket: "",
      messagingSenderId: "<messagingSenderId>"
    };
    firebase.initializeApp(config);
  }

我们正在触发按钮点击

onKeyUp(e)
    {
        if(e.keyCode===13 && trim(e.target.value) !== '')
        {
            e.preventDefault();
            let dbCon=this.props.db.database().ref('/messages');
            dbCon.push(
                {
                    message:trim(e.target.value)
                }
            );
            );
        }
    }

Database rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write:if true;
    }
  }
}

我们正面临这个问题。我在做什么错了?

Stack Trace:

Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied
    at index.cjs.js:13076
    at exceptionGuard (index.cjs.js:690)
    at Repo../node_modules/@firebase/database/dist/index.cjs.js.Repo.callOnCompleteCallback (index.cjs.js:13067)
    at index.cjs.js:12844
    at index.cjs.js:12019
    at PersistentConnection../node_modules/@firebase/database/dist/index.cjs.js.PersistentConnection.onDataMessage_ (index.cjs.js:12052)
    at Connection../node_modules/@firebase/database/dist/index.cjs.js.Connection.onDataMessage_ (index.cjs.js:11337)
    at Connection../node_modules/@firebase/database/dist/index.cjs.js.Connection.onPrimaryMessageReceived_ (index.cjs.js:11331)
    at WebSocketConnection.onMessage (index.cjs.js:11232)
    at WebSocketConnection../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.appendFrame_ (index.cjs.js:10837)
    at WebSocketConnection../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.handleIncomingFrame (index.cjs.js:10887)
    at WebSocket.mySock.onmessage (index.cjs.js:10784)

1 个答案:

答案 0 :(得分:1)

新手错误,正在使用较新的Firestore数据库,而不是使用实时数据库。更改为实时数据库可解决此问题。