Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 注销时无法读取null的属性“uid”_Firebase_Ionic4 - Fatal编程技术网

Firebase 注销时无法读取null的属性“uid”

Firebase 注销时无法读取null的属性“uid”,firebase,ionic4,Firebase,Ionic4,每次我从应用程序注销时,我都会 无法读取null的属性“uid” 从控制台。它导致参考以下代码: constructor( private firestore: AngularFirestore, private auth: AuthService, ) { firebase.auth().onAuthStateChanged(user => { if (this.currentUser == user) { this.currentUser = firebase.auth(

每次我从应用程序注销时,我都会

无法读取null的属性“uid”

从控制台。它导致参考以下代码:

constructor( private firestore: AngularFirestore, private auth: AuthService, ) 
{
firebase.auth().onAuthStateChanged(user => {
  if (this.currentUser == user) {
    this.currentUser = firebase.auth().currentUser;
    this.vendor = firebase.firestore().doc(`/Products/${this.currentUser.uid}`);
  }
});
onAuthStateChanged回调将在用户的身份验证状态发生更改时触发,因此无论用户何时登录或注销。在后一种情况下,用户将为null,这是您目前在代码中无法正确处理的

这看起来更正确:

firebase.auth().onAuthStateChanged(user => {
  this.currentUser = firebase.auth().currentUser;
  if (this.currentUser) {
    this.vendor = firebase.firestore().doc(`/Products/${this.currentUser.uid}`);
  }
});

this.currentUser=firebase.auth.currentUser;这是无用的,因为它已经具有相同的值。