Add function for delete User

FAVORITE_MUSICS_EKA
Emre KARTAL 2 years ago
parent 46a11ded7c
commit 5672edc715

@ -88,4 +88,28 @@ class AuthService {
void signOut() async {
await FirebaseAuth.instance.signOut();
}
Future<void> delete() async {
try {
User? currentUser = FirebaseAuth.instance.currentUser;
await MyApp.db
.collection("users")
.doc(currentUser?.uid)
.delete()
.then((value) => print("Firestore deleted user"))
.catchError(
(error) => print("Error deleting user from Firestore: $error"));
await currentUser?.delete();
await FirebaseAuth.instance.signOut();
} on FirebaseAuthException catch (e) {
if (e.code == 'requires-recent-login') {
throw ('Please log in again to delete your account');
}
rethrow;
} catch (error) {
rethrow;
}
}
}

@ -1,4 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '../main.dart';

@ -112,6 +112,10 @@ class UserViewModel {
authService.signOut();
}
delete() {
authService.delete();
}
bool isFriend(String id) {
return _userCurrent.followed.contains(id);
}

Loading…
Cancel
Save