onAngularFireAuthChanged(): void {
this.afAuth.authState.subscribe(async (user: firebase.User) => {
if (user && !(await this.afAuth.currentUser)) { // here is the place
// code
}
});
}
我可以使用await
运算符来编写上述类型的&&
吗?似乎对我不起作用。有任何线索吗?
this.afAuth.currentUser:
(property) currentUser: Promise<firebase.User>
答案 0 :(得分:1)
OP的反馈
是的,您是对的。我的代码工作正常。但是我的情况不正确。
原始
如有疑问,可以随时通过将await
从条件if
中移出来简化代码:
onAngularFireAuthChanged(): void {
this.afAuth.authState.subscribe(async (user: firebase.User) => {
const currentUser = await this.afAuth.currentUser;
if (user && !currentUser) { // here is the place
// code
}
});
}
我怀疑这是问题所在,您发布的代码应该可以正常工作。其他地方可能有问题。