“当集合名称错误并试图重定向时,如何从Firebase中删除项目时如何捕获错误”

时间:2019-04-22 00:43:31

标签: react-redux-firebase

我想删除我的Web应用程序(在Firestore中)中的帐户,然后仅在没有错误并且确实删除了帐户的情况下才重定向到主页。但是,即使在firestore中的集合名称不正确,“ react-redux-firebase”库仍会解析,因此无论集合名称是否正确,我的in然后块运行方法都将重定向到用户主页。方法返回Promise,但是我无法找到检查帐户是否已删除的方法,因为Promise返回的对象为空。...

onDeleteClick = () => {
    const { selectedClient, firestore } = this.props;

    let action = window.confirm(
      `Are you sure you want to delete ${selectedClient.firstName} ${
        selectedClient.lastName
      }?`
    );

    if (action) {
      firestore
        .delete({
          //This collection name is not correct
          collection: "clie1112312123nts",
          doc: selectedClient.id
        })
            // if I put an argument in the then() block it is value is undefined...
        .then(() => {        
            console.log("Account Deleted");
            this.props.history.push("/");
        })
        .catch(err => console.log(err));
    }
  };

0 个答案:

没有答案