无法编写Firebase数据库,出现空错误

时间:2018-07-28 12:07:47

标签: javascript firebase react-native firebase-realtime-database

曾经试图在我的react-native应用程序中使用像这样简单的东西写入我的Firebase实时数据库:

newTips = () => {
    firebase.database().ref('users/').set({
      tips: "tips"
    }).then((data)=>{
        //success callback
        console.log('data ' , data)
    }).catch((error)=>{
        //error callback
        console.log('error ' , error)
    })
  }

但是它没有写,我在世博会上收到了这个黄色消息。知道是什么问题吗? Auth可以完美地工作。

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

通过将Firebase Realtime更改为Firestore来解决此问题。完美运作。

newTips = () => {
    let user = firebase.auth().currentUser;
    let name, email, photoUrl, uid, emailVerified;
    firebase.auth().onAuthStateChanged(user => {

      if (user) {
        email = user.email;
        // User is signed in.
        console.log('Logged in user: ' + email)
        firestore.collection("tips").add({
            user: user.email,
            tips: "bla bla"
        })
        .then(function(docRef) {
            console.log("Document written with ID: ", docRef.id);
        })
        .catch(function(error) {
            console.error("Error adding document: ", error);
        });
      } else {
        // User is signed out.
        console.log('No user signed in')
      }
    })
  }