> ## 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 All Devices

> Revoke access for all devices except the current one, effectively logging out all other sessions

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

### Response

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

1. The current device's token is preserved
2. All other refresh tokens are blacklisted
3. All associated access tokens are blacklisted
4. The blacklisted 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:

  * 401 Unauthorized: Missing or invalid access token
  * 500 Internal Server Error: Invalid user ID in token
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tktchurch.com/v1/auth/devices/revoke-all" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
  ```

  ```javascript JavaScript theme={null}
  const revokeAllDevices = async (accessToken) => {
    const response = await fetch(
      'https://api.tktchurch.com/v1/auth/devices/revoke-all',
      {
        method: 'POST',
        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 revokeAllDevices('eyJhbGciOiJIUzI1NiIs...');
    console.log('All other devices revoked successfully');
  } catch (error) {
    console.error('Failed to revoke devices:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func revokeAllDevices(accessToken: String) async throws {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/auth/devices/revoke-all")!)
      urlRequest.httpMethod = "POST"
      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 revokeAllDevices(accessToken: "eyJhbGciOiJIUzI1NiIs...")
      print("All other devices revoked successfully")
  } catch {
      print("Failed to revoke devices: \(error.localizedDescription)")
  }
  ```

  ```kotlin Kotlin theme={null}
  class DeviceService(private val client: OkHttpClient) {
      suspend fun revokeAllDevices(accessToken: String) {
          val request = Request.Builder()
              .url("https://api.tktchurch.com/v1/auth/devices/revoke-all")
              .post(RequestBody.create(null, ByteArray(0)))
              .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 devices")
              }
          }
      }
  }

  // Usage
  try {
      deviceService.revokeAllDevices("eyJhbGciOiJIUzI1NiIs...")
      println("All other devices revoked successfully")
  } catch (e: Exception) {
      println("Failed to revoke devices: ${e.message}")
  }
  ```

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

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

  // Usage
  try {
    await revokeAllDevices('eyJhbGciOiJIUzI1NiIs...');
    console.log('All other devices revoked successfully');
  } catch (error) {
    console.error('Failed to revoke devices:', error.message);
  }
  ```
</RequestExample>

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

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

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