When a user deletes their account, it's crucial to also remove all associated assets stored in Supabase Storage to ensure privacy and data integrity. Here's a step-by-step guide on how to implement this functionality using FlutterFlow and Supabase.
Supabase is an open-source Backend-as-a-Service (BaaS) platform that offers a scalable backend for building web and mobile applications. It provides developers with tools to set up a complete backend without manually configuring databases or authentication systems. Supabase is often described as an alternative to Google Firebase, but with a stronger focus on open-source technologies and relational databases like PostgreSQL.
Follow the steps below to set up your Supabase project:
Project URL
and API Key
(usually the anon
public key). You'll need these to configure the client-side.Go to the supabase storage and create new bucket there( ex : - Assets).
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.
Follow the steps below to set up your FlutterFlow project:
Here in the above action we pass the Bucket Name(Assets) and Upload Folder Path(User ID).
In supabase storage the uploaded file will be stored like, Assets → User ID → Uploaded File.
Delete Accoount Button Action : - Delete button action we used two custom actions, one for delete authenticated user’s all assets from supabase storage ****and another one for delete user account. you can even combine both custom action into one custom action.
// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.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!
Future deleteAssetsFromStorage(
String bucketName,
String folderPath,
) async {
// Add your function code here!
final supabase = Supabase.instance.client;
try {
// List all files in the folder
final List<FileObject> files =
await supabase.storage.from(bucketName).list(path: folderPath);
if (files.isNotEmpty) {
// Prepare the list of file paths to delete
final List<String> filePaths = files.map((file) => file.name).toList();
// Delete all files in the folder
final response = await supabase.storage
.from(bucketName)
.remove(filePaths.map((file) => '$folderPath/$file').toList());
if (response.length > 0) {
print('Folder $folderPath deleted successfully');
} else {
print('Error deleting folder: ');
}
} else {
print('No files found in the folder: $folderPath');
}
} catch (error) {
print('Error deleting folder: $error');
}
}
// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.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!
Future deleteUserAccount(
String userId,
String supabaseURL,
String serviceRoleSecretKey,
) async {
// Add your function code here!
final supabase = SupabaseClient(supabaseURL, serviceRoleSecretKey);
await supabase.auth.admin.deleteUser(userId);
}
Integrating account deletion functionality in your app is essential for maintaining user privacy and data integrity. By following the steps outlined in this guide, you can effectively delete a user's account along with all their associated assets stored in Supabase Storage using FlutterFlow. Leveraging Supabase's robust backend capabilities and FlutterFlow's low-code environment simplifies the process, enabling you to deliver a seamless and secure user experience. This approach not only ensures compliance with data privacy standards but also enhances user trust in your application.