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
Javascript Firebase身份验证:can';t删除从currentUser返回的承诺中的Firestore文档。删除()_Javascript_Firebase_Google Cloud Firestore_Firebase Authentication_Angularfire2 - Fatal编程技术网

Javascript Firebase身份验证:can';t删除从currentUser返回的承诺中的Firestore文档。删除()

Javascript Firebase身份验证:can';t删除从currentUser返回的承诺中的Firestore文档。删除(),javascript,firebase,google-cloud-firestore,firebase-authentication,angularfire2,Javascript,Firebase,Google Cloud Firestore,Firebase Authentication,Angularfire2,我在应用程序中使用firebase身份验证和angularfirestore,遇到了一个奇怪的问题。如下图所示,在firebase auth中删除用户后,我想删除firestore中的用户文档,但firestore部分不起作用 编辑2:在代码中,this.currentUser与angularFireAuth.auth.currentUser不同。这是我单独创建的一个局部变量 return this.angularFireAuth.auth.currentUser.delete().then((

我在应用程序中使用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:添加了捕获,但未打印任何内容

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;
    }
  }
}

你所观察到的对我来说很有意义

如果您在Firestore上设置了需要经过身份验证的用户才能删除文档的安全规则,则删除用户帐户后文档将无法删除(因为用户不再经过身份验证)。在注销或删除用户帐户之前,您肯定希望在进行身份验证时尽一切所能


您应该在代码中添加错误检查,以查明文档删除是否出错。现在,您在承诺链上没有任何
catch
回调,因此您永远不会知道是否出现了问题。由于安全规则拒绝请求,我怀疑您会在文档删除中看到“权限被拒绝”类型的错误。

我认为发生的情况是,在执行
auth.currentUser.delete()
之后,
此.currentUser
也会被清除(如果它保持
auth.currentUser


所以您只是删除了没有失败的
doc(“”
)。但是没有这样的文档,所以您不会看到任何内容。

您好,我添加了catch回调,但是在控制台中没有打印任何内容(这很奇怪,因为如果请求未通过,我会预期会出现一些错误?)。此外,我没有任何要求用户进行身份验证的安全规则,即使您没有自己编写安全规则,也可能在项目创建时创建了如下安全规则。所以要注意这一点。Daruul在他的评论中说得很有道理,若安全规则存在,那个么若用户并没有登录,我们就不能执行该操作。我的安全规则允许所有操作,所以不能这样。请编辑问题以显示您的安全规则。如果您在文档写入后没有得到某种结果,那么您应该向angularfire提交一个bug,并说明具体的复制步骤。这是我的错,我没有明确说明this.currentUser是一个不受auth.currentUser()影响的局部变量。我已经用console.log对它进行了测试,而this.currentUser不是null,因此我问了这个问题。真糊涂