extensions icon indicating copy to clipboard operation
extensions copied to clipboard

[Delete-user-data] Question: How to delete one to many relations?

Open Berki2021 opened this issue 4 years ago • 4 comments

I would like to use the "delete-user-data" extension, but I have a problem: We use firebase for an ecommerce app and the users can make purchases. These purchases are saved in cloud-firestore as:

purchases --> Random UID: - UserID: UserUID - OrderDate: Date - Amount: XYZ - ETC

My question is: How can I configure my "cloud-firestore-paths" in the user-delete-extension in order to delete any purchase which the customer made, e.g. any purchases-document which contains the particular user-uid?

Berki2021 avatar Oct 19 '21 10:10 Berki2021

Based on the following thread, it's not possible

  • https://github.com/firebase/extensions/issues/305

You have to write your own firebase function. You can be inspired by this extension

  • https://github.com/firebase/extensions/blob/master/delete-user-data/functions/src/index.ts

Or in the thread above there is a gist of advanced delete-user-data feature

  • https://gist.github.com/TylerAHolden/10d0ee986a8a1f743fa09154118b177b

ostatnicky avatar Oct 19 '21 11:10 ostatnicky

@Berki2021 thanks for the request. Since there was also another thread (#305) asking for the same feature we're going to take a deeper look into it.

i14h avatar Nov 23 '21 17:11 i14h

@Berki2021 are you willing to help us understand what your needs are? If so can you reach out to my email ([email protected]) ?

i14h avatar Nov 23 '21 17:11 i14h

Hi, in our use case we also need a similar implementation. We have a model or object which is many to many with different users, so if a user wish to delete the account, we should delete all the user data, so we should search a collection base on the userId who is deleting the account and delete all the records that belongs to the user.

Not sure if I'm explaining correctly but I think is a common usecase, another one is that there is a collection where a user can create as many records as they want, but is a parent collection, so there is a field for the owner of the record.

I think for now we will make our own implementation, but I really believe this can be a common use case specially with apple now making mandatory the account deletion within the app, so probably a lot more people wants to use this extension

https://developer.apple.com/news/?id=mdkbobfo

unxavi avatar Dec 13 '21 17:12 unxavi

Hi all,

I'm just going through some long running issues across the extensions repo.

I think the current version of the extension has an "Auto Discovery" feature, which should support your scenario:

Since your purchase documents contain a UserID field that matches the user's UID, you can enable auto discovery and specify the field to search for. You should configure the extension as follows:

  1. Set Enable auto discovery to true
  2. Set Auto discovery search fields to UserID
  3. Set Auto discovery search depth to an appropriate level (default 3 should work for your case)

Hopefully this resolves the issue.

I'm going to close this as complete for now, but if this does not resolve the issue or i've misunderstood, feel free to reply or reopen the issue!

cabljac avatar Feb 12 '25 12:02 cabljac