deleteDevice method

Future<void> deleteDevice(
  1. String deviceId, {
  2. AuthenticationData? auth,
})

This API endpoint uses the User-Interactive Authentication API.

Deletes the given device, and invalidates any access token associated with it.

deviceId The device to delete.

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

Implementation

Future<void> deleteDevice(String deviceId, {AuthenticationData? auth}) async {
  final requestUri =
      Uri(path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}');
  final request = Request('DELETE', 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(),
    }),
  );
  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 ignore(json);
}