Firebase 注销时无法读取null的属性“uid”
每次我从应用程序注销时,我都会 无法读取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(
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;这是无用的,因为它已经具有相同的值。