Reactjs 使用firebase在React js中工作:TypeError:无法读取属性';uid';空的
这是我的代码:Reactjs 使用firebase在React js中工作:TypeError:无法读取属性';uid';空的,reactjs,firebase-realtime-database,firebase-authentication,Reactjs,Firebase Realtime Database,Firebase Authentication,这是我的代码: 48 | let allevents = []; 49 | 50 | > 51 | database.child("myevents").child(firebase.auth().currentUser.uid).on("value", function(snapshot){ ^ 52 | 53 | snapshot.forEach(function(childSnapshot) { 54 | v
48 | let allevents = [];
49 |
50 |
> 51 | database.child("myevents").child(firebase.auth().currentUser.uid).on("value", function(snapshot){
^
52 |
53 | snapshot.forEach(function(childSnapshot) {
54 | var obj = childSnapshot.val();
从:
注意:currentUser也可能为null,因为auth对象尚未完成初始化
因此,在您的情况下,您需要检查用户
是否存在于onAuthStateChanged
回调中:
let allevents = [];
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
database.child("myevents").child(user.uid).on("value", ...)
} else {
// No user is signed in.
}
});
可能重复的