Firebase - 无法读取null的属性'uid'

时间:2018-03-18 16:16:41

标签: json firebase firebase-realtime-database

当我运行此代码时,出现错误Uncaught TypeError: Cannot read property 'uid' of null。为什么会这样?我上面有一些非常相似的代码,但运行正常。这是错误抛出的代码:

  function checkForSession(testNo) {
    user = firebase.auth().currentUser;
    firebase.database().ref("users/" + user.uid + "/tests/" + testNo).on('value', function(snapshot) {
        var datas = snapshot.val();
        hour = datas.lastActiveHour;
        minute = datas.lastActiveMinute;
        day = datas.lastActiveDay;
        month = datas.lastActiveMonth;
        year = datas.lastActiveYear;
        pos = datas.position;
        console.log("Last position: " + pos);
    });
  }

0 个答案:

没有答案