When a user deletes their account, it is important to also remove all their associated assets stored in Firebase storage to maintain data integrity and ensure privacy. Here's an overview of how this process works in Firebase:
FlutterFlow is a low-code development platform built on top of Flutter, Google's open-source UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.
To set up your Flutterflow project, please follow the steps below:
Firebase is a Google platform offering tools to build, improve, and scale apps across mobile, web, and desktop, with services like real-time databases, authentication, and serverless backend solutions.
To set up your Firebase project, please follow the steps below:
If a user want to delete his account form the app then make sure his also remove all their associated assets from firebase storage. For we need to Create a custom action for that.
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:firebase_storage/firebase_storage.dart';
Future deleteUserFiles(String userId) async {
// Add your function code here!
try {
// Reference to the user's folder
final userFolderRef = FirebaseStorage.instance.ref('users/$userId/uploads');
// List all files and subfolders in the user's folder
final listResult = await userFolderRef.listAll();
print("check length");
print(listResult.items);
// Delete all files
for (var fileRef in listResult.items) {
await fileRef.delete();
print('Deleted file: ${fileRef.fullPath}');
}
// Recursively delete subfolders (if any)
for (var folderRef in listResult.prefixes) {
await deleteUserFiles(folderRef.fullPath);
}
print('User folder deleted successfully.');
} catch (e) {
print('Error deleting user folder: $e');
}
}
The custom action taking only one argument that was userId. So in that you need to send document reference of the authenticated user on the click of delete Account button.
By structuring user assets logically and leveraging Firebase Authentication triggers and Cloud Functions, you can ensure that when a user deletes their account, all their associated assets are securely and efficiently deleted.