Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"useFirestoreForProfile" leads to trigger update twice with a preceding async document delete #1176

Open
bookhahn opened this issue Apr 7, 2022 · 0 comments

Comments

@bookhahn
Copy link

bookhahn commented Apr 7, 2022

Hi!

I want to delete and update a couple of docs in a redux action, but I have boiled down the problem to the following:

const rrfConfig = {
    userProfile: "users",
    enableClaims: true,
    useFirestoreForProfile: true,
    attachAuthIsReady: true,
};

export const deleteEmployee = async (employee, profile) => {
  const employeeRef = firestore.collections("employees").doc(employee.id);
  const accountRef = firestore.collections("users").doc(profile.uid);
  try {
    await employeeRef.delete();
    await accountRef.update({count: firebase.firestore.FieldValue.increment(1)});
  } catch (error) {
    console.error(error.message);
  }
}

If I run the above code, the user document gets updated twice leading to:
profile.count == 2

If I don't set "useFirestoreForProfile", it works as expected:
user.count == 1

If I don't have another document delete or update before updating the user document, it does work, too. (even with "useFirestoreForProfile" == true)
Even if I am running this from outside via node it works as expected.
That is why I am considering this as a bug.

Note: I am using firebase emulators.

firebase@10.5.0
react-redux-firebase@3.3.1

@bookhahn bookhahn changed the title "useFirestoreForProfile" leads to trigger update twice with a preceding async await. "useFirestoreForProfile" leads to trigger update twice with a preceding async document delete Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant