当我运行此代码时,出现错误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);
});
}