每次我从应用程序注销时,我都会得到
从控制台无法读取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}`);
}
});
答案 0 :(得分:1)
只要用户的身份验证状态更改(无论他们登录还是注销),onAuthStateChanged
回调都会触发。在后一种情况下,user
将是null
,您现在无法在代码中正确处理它。
这看起来更正确:
firebase.auth().onAuthStateChanged(user => {
this.currentUser = firebase.auth().currentUser;
if (this.currentUser) {
this.vendor = firebase.firestore().doc(`/Products/${this.currentUser.uid}`);
}
});