When I run this code, I get an error Uncaught TypeError: Cannot read property 'uid' of null
. Why does this happen? I have some very similar code above it but that runs fine. Here is the error-throwing code:
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);
});
}