FlutterflowDevs
 · FlutterFlow App Development Agency

Automatic Asset Deletion on Account Removal in Firebase

When a user deletes their account, it's essential to remove all associated files from Firebase Storage to ensure privacy. This guide covers setting up FlutterFlow and Firebase to achieve this.

Setup Overview

  1. Create a FlutterFlow Project – Set up a new project in the FlutterFlow console.

  2. Firebase Configuration – Create a Firebase project, enable authentication, and connect it to FlutterFlow.

Deleting User Files from Firebase Storage

When a user clicks Delete Account, a custom action should remove their stored files before deleting the account.

Custom Action Code

Future deleteUserFiles(String userId) async {
 try {
 final userFolderRef = FirebaseStorage.instance.ref('users/$userId/uploads'); 
 final listResult = await userFolderRef.listAll(); 
 for (var fileRef in listResult.items) { 
   await fileRef.delete(); 
 } 
 for (var folderRef in listResult.prefixes) 
  { 
    await deleteUserFiles(folderRef.fullPath); 
  } 
 print('User folder deleted successfully.'); 
 } catch (e) { 
   print('Error deleting user folder: $e'); 
 } 
}

Pass the authenticated userId when calling this function upon account deletion.

Conclusion

This approach ensures all user assets and account data are securely removed.

For more details, please check the full blog below.
https://www.flutterflowdevs.com/blog/remove-all-assets-uploaded-by-the-user-in-firebase-when-user-delete-their-account

6