forked from vandadnp/flutter-tips-and-tricks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase-batch-operations-in-flutter.dart
More file actions
32 lines (31 loc) · 1.01 KB
/
firebase-batch-operations-in-flutter.dart
File metadata and controls
32 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 🐦 Twitter https://twitter.com/vandadnp
// 🔵 LinkedIn https://linkedin.com/in/vandadnp
// 🎥 YouTube https://youtube.com/c/vandadnp
// 💙 Free Flutter Course https://linktr.ee/vandadnp
// 📦 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY
// 🤝 Want to support my work? https://buymeacoffee.com/vandad
Future<bool> deleteAccountAndDocuments() async {
final auth = FirebaseAuth.instance;
final user = auth.currentUser;
if (user == null) {
return false;
}
final userId = user.uid;
// delete user documents
try {
final store = FirebaseFirestore.instance;
final operation = store.batch();
final collection = await store.collection(userId).get();
for (final document in collection.docs) {
operation.delete(document.reference);
}
await operation.commit();
// delete the user
await user.delete();
// log the user out
await auth.signOut();
return true;
} catch (_) {
return false;
}
}