2016-12-12 25 views
1

我想在我的Electron + React + Redux應用程序中使用Firebase SDK。Firebase在電子應用程序中默默失敗

所以在我的減速器我有這些:

import firebase from 'firebase' 

// Initialize Firebase 
var config = { 
    apiKey: "...", 
    authDomain: "....firebaseapp.com", 
    databaseURL: "https://....firebaseio.com", 
    storageBucket: "....appspot.com", 
    messagingSenderId: "..." 
}; 

firebase.initializeApp(config); 

... 

case XYZ: 

    firebase.database().ref().on("value", function(snapshot) { 
     console.log("Hello World") 
    }) 

回調永遠不會被調用。我試着將這段代碼放在我的componentDidMount回調中,在我的redux動作文件中,沒有任何工作。它靜靜地失敗,控制檯中沒有錯誤。

回答

0

問題在於Firebase數據庫規則。在嘗試讀取/寫入操作之前,我沒有驗證本地會話。

所以它是:

{ 
    "rules": { 
     ".read": "auth != null", 
     ".write": "auth != null" 
    } 
} 

我把它改爲:

{ 
    "rules": { 
     ".read": "auth == null", 
     ".write": "auth == null" 
    } 
} 

這可能不是大多數人想要做的,用火力地堡驗證,而不是驗證會話,它會工作。

但令人討厭的是,代碼不會拋出任何類型的錯誤。很難調試。