【发布时间】:2020-11-25 18:25:09
【问题描述】:
我在我的应用程序中使用了 firebase 身份验证和 angularfirestore,但遇到了一个奇怪的问题。如下图所示,在删除 firebase auth 中的用户后,我想删除 firestore 中的用户文档,但 firestore 部分不起作用。
编辑 2:在代码中,this.currentUser 与 angularFireAuth.auth.currentUser 不同。这是我单独创建的局部变量。
return this.angularFireAuth.auth.currentUser.delete().then(() => {
this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
});
})
但是,如果我先从 firestore 中删除文档,然后再从 firebase auth 中删除用户,它就可以工作。
return this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
return this.angularFireAuth.auth.currentUser.delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
});
})
有人知道为什么会这样吗?他们都返回承诺,所以我希望行为是相同的。
编辑 1:添加了 catch,但没有打印任何内容
return this.angularFireAuth.auth.currentUser.delete().then(() => {
return this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
}, (error) => {
console.log(error);
});
}, (error) => {
console.log(error);
})
编辑 3: 安全规则
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
【问题讨论】:
标签: javascript firebase google-cloud-firestore firebase-authentication angularfire2