I want to delete an account in my web application (in firestore) and then redirect to main page only if there is no error and account indeed is deleted. However 'react-redux-firebase' library resolves even if the name of collection in firestore is not correct, and therefore my methods in then block run and user is redirected in any case to main page, whether collection name is correct or not . Methods returns Promise, but i cannon find the way to check if account was deleted or not, because object that Promise returns is empty....

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 Answers