> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tktchurch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Revoke Device

> Revoke access for a specific device, invalidating its tokens

<Note>
  This endpoint requires authentication. Include the JWT access token in the Authorization header.
</Note>

### Path Parameters

<ParamField path="id" type="string" required>
  The UUID of the device token to revoke
</ParamField>

### Response

A successful request returns HTTP 204 No Content status. The following actions are performed:

1. The device's refresh token is blacklisted
2. Any associated access tokens are blacklisted
3. The tokens are removed from the database

### Error Responses

<ResponseField name="error" type="object">
  Error details when the request fails

  <Expandable title="Error Object">
    <ResponseField name="status" type="integer">
      HTTP status code
    </ResponseField>

    <ResponseField name="reason" type="string">
      Error message explaining why the request failed
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  Common error cases:

  * 400 Bad Request: Invalid device ID format
  * 401 Unauthorized: Missing or invalid access token
  * 404 Not Found: Device not found or belongs to another user
  * 500 Internal Server Error: Invalid user ID in token
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.tktchurch.com/v1/auth/devices/123e4567-e89b-12d3-a456-426614174000" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
  ```

  ```javascript JavaScript theme={null}
  const revokeDevice = async (accessToken, deviceId) => {
    const response = await fetch(
      `https://api.tktchurch.com/v1/auth/devices/${deviceId}`,
      {
        method: 'DELETE',
        headers: {
          'Authorization': `Bearer ${accessToken}`
        }
      }
    );

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error.reason);
    }

    return response.status === 204;
  };

  // Usage
  try {
    await revokeDevice(
      'eyJhbGciOiJIUzI1NiIs...', // access token
      '123e4567-e89b-12d3-a456-426614174000' // device ID
    );
    console.log('Device revoked successfully');
  } catch (error) {
    console.error('Failed to revoke device:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func revokeDevice(accessToken: String, deviceId: UUID) async throws {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/auth/devices/\(deviceId)")!)
      urlRequest.httpMethod = "DELETE"
      urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
      
      let (_, response) = try await URLSession.shared.data(for: urlRequest)
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      if httpResponse.statusCode != 204 {
          throw URLError(.badServerResponse)
      }
  }

  // Usage
  do {
      try await revokeDevice(
          accessToken: "eyJhbGciOiJIUzI1NiIs...",
          deviceId: UUID(uuidString: "123e4567-e89b-12d3-a456-426614174000")!
      )
      print("Device revoked successfully")
  } catch {
      print("Failed to revoke device: \(error.localizedDescription)")
  }
  ```

  ```kotlin Kotlin theme={null}
  class DeviceService(private val client: OkHttpClient) {
      suspend fun revokeDevice(accessToken: String, deviceId: String) {
          val request = Request.Builder()
              .url("https://api.tktchurch.com/v1/auth/devices/$deviceId")
              .delete()
              .header("Authorization", "Bearer $accessToken")
              .build()

          client.newCall(request).execute().use { response ->
              if (!response.isSuccessful) {
                  val error = response.body?.string()?.fromJson<ErrorResponse>()
                  throw Exception(error?.reason ?: "Failed to revoke device")
              }
          }
      }
  }

  // Usage
  try {
      deviceService.revokeDevice(
          "eyJhbGciOiJIUzI1NiIs...", // access token
          "123e4567-e89b-12d3-a456-426614174000" // device ID
      )
      println("Device revoked successfully")
  } catch (e: Exception) {
      println("Failed to revoke device: ${e.message}")
  }
  ```

  ```typescript React Native theme={null}
  import axios from 'axios';

  const revokeDevice = async (accessToken: string, deviceId: string): Promise<void> => {
    try {
      await axios.delete(
        `https://api.tktchurch.com/v1/auth/devices/${deviceId}`,
        {
          headers: {
            'Authorization': `Bearer ${accessToken}`
          },
        }
      );
    } catch (error) {
      if (axios.isAxiosError(error)) {
        throw new Error(error.response?.data?.error?.reason || 'Failed to revoke device');
      }
      throw error;
    }
  };

  // Usage
  try {
    await revokeDevice(
      'eyJhbGciOiJIUzI1NiIs...', // access token
      '123e4567-e89b-12d3-a456-426614174000' // device ID
    );
    console.log('Device revoked successfully');
  } catch (error) {
    console.error('Failed to revoke device:', error.message);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 204 No Content theme={null}
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": {
      "status": 400,
      "reason": "Invalid device ID format"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": {
      "status": 401,
      "reason": "Invalid or expired access token"
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "error": {
      "status": 404,
      "reason": "Device not found"
    }
  }
  ```

  ```json 500 Internal Server Error theme={null}
  {
    "error": {
      "status": 500,
      "reason": "Invalid user ID in token"
    }
  }
  ```
</ResponseExample>
