deactivateAccount method

Future<IdServerUnbindResult> deactivateAccount({
  1. AuthenticationData? auth,
  2. String? idServer,
})
inherited

Deactivate the user's account, removing all ability for the user to login again.

This API endpoint uses the User-Interactive Authentication API.

An access token should be submitted to this endpoint if the client has an active session.

The node may change the flows available depending on whether a valid access token is provided.

Unlike other endpoints, this endpoint does not take an id_access_token parameter because the node is expected to sign the request to the identity server instead.

auth Additional authentication information for the user-interactive authentication API.

idServer The identity server to unbind all of the user's 3PIDs from. If not provided, the node MUST use the id_server that was originally use to bind each identifier. If the node does not know which id_server that was, it must return an id_server_unbind_result of no-support.

returns id_server_unbind_result: An indicator as to whether or not the node was able to unbind the user's 3PIDs from the identity server(s). success indicates that all identifiers have been unbound from the identity server while no-support indicates that one or more identifiers failed to unbind due to the identity server refusing the request or the node being unable to determine an identity server to unbind from. This must be success if the node has no identifiers to unbind for the user.

Implementation

Future<IdServerUnbindResult> deactivateAccount(
    {AuthenticationData? auth, String? idServer}) async {
  final requestUri = Uri(path: '_api/client/v3/account/deactivate');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (auth != null) 'auth': auth.toJson(),
    if (idServer != null) 'id_server': idServer,
  }));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return IdServerUnbindResult.values
      .fromString(json['id_server_unbind_result'] as String)!;
}