delete method

Future<AuthResponse<T>> delete({
  1. Object? args,
  2. String? id,
  3. bool notifiable = true,
})

Implementation

Future<AuthResponse<T>> delete({
  Object? args,
  String? id,
  bool notifiable = true,
}) async {
  emit(
    const AuthResponse.loading(Provider.none, AuthType.delete),
    args: args,
    id: id,
    notifiable: notifiable,
  );
  final data = await auth;
  if (data == null) {
    return emit(
      AuthResponse.rollback(
        data,
        msg: msg.loggedIn.failure,
        provider: Provider.none,
        type: AuthType.delete,
      ),
      args: args,
      id: id,
      notifiable: notifiable,
    );
  }

  try {
    final response = await delegate.delete();
    if (!response.isSuccessful) {
      return emit(
        AuthResponse.rollback(
          data,
          msg: response.message,
          provider: Provider.none,
          type: AuthType.delete,
        ),
        args: args,
        id: id,
        notifiable: notifiable,
      );
    }

    await _delete();
    await _backup.onDeleteUser(data.id);

    return emit(
      AuthResponse.unauthenticated(
        msg: msg.delete.done,
        provider: Provider.none,
        type: AuthType.delete,
      ),
      args: args,
      id: id,
      notifiable: notifiable,
    );
  } catch (error) {
    return emit(
      AuthResponse.rollback(
        data,
        msg: msg.delete.failure ?? error,
        provider: Provider.none,
        type: AuthType.delete,
      ),
      args: args,
      id: id,
      notifiable: notifiable,
    );
  }
}