简体   繁体   中英

Firebase - Delete a User with all related Data (iOS, Objective-c)

I am having problems with the deletion logic of firebase users. The problem is: How do I delete a user and then delete all his data, when the security settings allow only authenticated users to manipulate the database?

NSString *userUID = user.uid;
[user deleteWithCompletion:^(NSError *_Nullable error) {
      if (error) {
      }
      else {
           // Account deleted.
           [[[_ref child:@"user_info"] child:userUID] removeValue];
      }
 }];

In the logs: setValue: or removeValue: at /user_info/jKXh5g1t2kbaHIqKTiz75PTGhc33 failed: permission_denied

What is the best practice here? Do I need to change the security rules or is there an appropriate code logic for this case?

I thank you for any help!

You have a few options here.

  1. The first option is to delete the user data from the database before the account is deleted. This means you can trigger the deletion from the app itself, so don't have the security problem.

  2. The second option is to delete the user data immediately after the user account is deleted from Cloud Functions. These functions run in a trusted environment, so (using the Admin SDK) have full administrative access to your database. You'll trigger your function when the user account is deleted and clean up the database.

  3. There is an entire github repo that aids in this kind of data cleanup: user-data-protection . It's based on the same Cloud Functions trigger as the previous example, but covers much more extensive data cleanup in a declarative way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM