deleteUser method

Future<User?> deleteUser(
  1. String email,
  2. String password
)

Deletes the current user after re-authentication.

Returns the User object if the deletion is not completed, usually due to failed re-authentication.

Implementation

Future<User?> deleteUser(String email, String password) async {
  try {
    await reauthenticate(email, password);
    print("Reauthenticated");
    await FirebaseAuth.instance.currentUser!.delete();
    print("User Deleted Successfully");
    return FirebaseAuth.instance.currentUser;
  } on FirebaseAuthException catch (e) {
    if (e.code == 'requires-recent-login') {
      print(
          'The user must reauthenticate before this operation can be executed.');
    }
  }
  return null;
}