wpUserDelete method

Future<WPUserDeleteResponse> wpUserDelete({
  1. required String password,
  2. String? userToken,
})

Sends a request to delete the user's WordPress account. The user's current password is required.

On success the account and all its tokens are deleted, and the stored session is removed from the device (unless userToken belongs to a different user than the stored one).

Returns a WPUserDeleteResponse future. Throws an IncorrectPasswordException if the password is wrong, InvalidUserTokenException if the token is not valid.

Implementation

Future<WPUserDeleteResponse> wpUserDelete(
    {required String password, String? userToken}) async {
  // send http request
  final Map<String, dynamic> json = await _http(
    method: "POST",
    url: _urlForRouteType(WPRouteType.UserDelete),
    userToken: userToken,
    shouldAuthRequest: true,
    body: {"password": password},
  );

  String? storedToken = await WPJsonAPI.wpUserToken();
  if (userToken == null || userToken == storedToken) {
    await WPJsonAPI.wpLogout();
  }
  return WPUserDeleteResponse.fromJson(json);
}