Firebase user.delete()方法有效,但出现错误

Firebase user.delete()方法有效,但出现错误,firebase,google-cloud-firestore,firebase-authentication,angular10,Firebase,Google Cloud Firestore,Firebase Authentication,Angular10,我使用angular,并且有一个存储用户详细信息和登录信息的应用程序。尝试删除用户时,我首先删除所有与用户相关的信息。然后要求用户重新对自己进行身份验证,身份验证后,用户将注销,并获取其基本详细信息以显示已删除的配置文件id,然后使用user.delete()显示其登录信息 所有这些都像预期的那样工作,但最后我得到了一个错误。为什么即使我已经注销了应用程序的用户,也会出现此错误 错误消息:{code:“身份验证/用户令牌已过期”,消息:“用户的凭据不再有效。用户必须重新登录。”,a:null}

我使用angular,并且有一个存储用户详细信息和登录信息的应用程序。尝试删除用户时,我首先删除所有与用户相关的信息。然后要求用户重新对自己进行身份验证,身份验证后,用户将注销,并获取其基本详细信息以显示已删除的配置文件id,然后使用user.delete()显示其登录信息

所有这些都像预期的那样工作,但最后我得到了一个错误。为什么即使我已经注销了应用程序的用户,也会出现此错误

错误消息:
{code:“身份验证/用户令牌已过期”,消息:“用户的凭据不再有效。用户必须重新登录。”,a:null}

我的代码-

  deleteAccount(){
    var userToDelete = firebase.auth().currentUser;
    this.logout();
    this.store.dispatch(UI.StartAppLoad({status:'Deleting User Details...'}));

    this.userService.DeleteUser(userToDelete.uid)
    .then((res)=>{
      console.log(res);
    }).catch(this.HandleError.bind(this));

    userToDelete.delete().then(
      (res)=>{
        console.log(res);
        this.uiService.showSnackbar('User Account Deleted',null,3000);
        this.store.dispatch(UI.LoadApp());
      }
    ).catch(this.HandleError.bind(this));
  }

  logout() {
    this.afAuth.signOut();
  }
其中,
HandleError
用于在snackbar中显示错误消息

deleteCount()
在用户成功进行身份验证后调用

我不想显示错误消息,而是想显示消息
“用户帐户已删除”

全流-

  onDeleteAccount(){
    const confirmResult = this.uiService.showConfirm({
      isDanger:true,
      title:'Delete Account?',
      content:'All your user account data will be permamnently deleted.'+
              ' You will need to create a new account later. Are you sure you want to continue?',
      okText:'Delete'
    });
    confirmResult.subscribe(async isDelete=>{
      if(isDelete){
        this.store.dispatch(UI.StartAppLoad({status:'Deleting Excercise Data...'}));
        const isResetDone = await this.trainingService.resetPastExercise();
        if(isResetDone){
          this.store.dispatch(UI.StartAppLoad({status:'Deleting Follow list...'}));
          this.userService.clearFollowList();
          this.authService.actionToPerform.next(actions.Delete_Account);
          this.store.dispatch(UI.LoadApp());
          this.router.navigate([AppRoutes.ReAuthenticate]);
        }
      }
    });
  }
验证页面的
submit()
方法:

this.authService.reauthenticate({
  email:form.value.email,
  password:form.value.password
});

this.authService.deleteAccount();
授权服务:

reauthenticate(authdata: AuthData) {
    this.store.dispatch(UI.StartLoading());
    var credential = firebase.auth.EmailAuthProvider.credential(
      authdata.email,
      authdata.password
    );
    this.afAuth.currentUser.then((user) => {
      user.reauthenticateWithCredential(credential)
        .then((res)=>{
          this.prevPwd = authdata.password;
          console.log(res);
          this.store.dispatch(UI.StopLoading());
        })
        .catch(this.HandleError.bind(this))
    });
  }
然后使用上述方法
deleteCount()

请建议。

如中所述,发生这种情况的原因是:

delete()
是一种安全敏感操作,要求用户 最近已登录

该文件还指出:

如果不满足此要求,请询问用户 再次验证,然后调用
firebase.User.reauthenticateWithCredential


因此,您需要处理此特定错误,并按照文档指示执行操作,即“请用户再次验证,然后再调用。”

您好,在使用此方法之前,我已调用了
user.reauthenticateWithCredential()
,并且仅当用户已成功对自己进行身份验证时,才会调用此方法。请查看帖子。我已经添加了整个流程。如果我没有弄错的话,我看不到您的代码中有任何地方可以调用
reaauthenticatewithcredential()
。很抱歉,我没有在此处添加该部分。它是从
reaauthenticate()
方法中调用的\N