firebase@3.3.0
react-native v0.32台通过wifi在安卓设备上测试
Firebase数据库没有任何身份验证规则,它是开放读写的.
考虑到以下文件 struct :
|_ firebase.js
|_ actions.js
这不管用:
firebase.js
import firebase from 'firebase'
const config = {
apiKey: "*****",
authDomain: "****",
databaseURL: "*****",
storageBucket: "*****",
}
firebase.database.enableLogging(true);
export default firebase.initializeApp(config)
actions.js
import firebase from './firebase'
export const fetchData = () => {
const Data = firebase.database().ref('some/data')
Data.on('value', (snapshot) => {
console.log("snapshot", snapshot.val()) // never printed
}, (error) => {
console.error(error)
})
}
debug output
p:0: Browser went online.
firebase-database.js:36 p:0: Listen called for /some/data default
firebase-database.js:36 p:0: Making a connection attempt
没有别的了...
This does work (but it's not a solution) :
firebase.js
...same content as above...
export default () => firebase.initializeApp(config) // we export a function instead to trigger the initialization when the app is ready
actions.js
...same content as above...
const Data = firebase().database().ref('some/data') // we "manually" trigger the initialization, it's obviously not a good solution since we can't initialize the app multiple times
output
p:0: Browser went online.
firebase-database.js:36 p:0: Listen called for /some/data default
firebase-database.js:36 p:0: Making a connection attempt
firebase-database.js:36 p:0: Auth token refreshed
firebase-database.js:36 getToken() completed. Creating connection.
firebase-database.js:36 c:0:0: Connection created
我做错了什么?我还注意到,一旦输入import firebase from 'firebase'
,firebase
变量在所有文件中全局可用,这些文件不是import语句中的firebase
变量(我本可以写import FooBar from 'firebase'
,firebase
全局变量仍然被导入)