> ## 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.

# Unlink Provider

> Remove a linked authentication provider from the current account

<Note>
  This endpoint requires authentication.
</Note>

### Request Body

<ParamField body="provider" type="string" required>
  The provider to unlink. One of:

  * `google`: Google OAuth authentication
  * `facebook`: Facebook OAuth authentication
  * `apple`: Apple Sign In authentication
</ParamField>

### Response

A successful request returns HTTP 200 OK status. The provider is unlinked from the current user's account.

### 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 provider value
  * 400 Bad Request: Cannot remove last authentication method
  * 401 Unauthorized: Missing or invalid access token
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tktchurch.com/v1/auth/unlink-provider" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
    -H "Content-Type: application/json" \
    -d '{
      "provider": "google"
    }'
  ```

  ```javascript JavaScript theme={null}
  const unlinkProvider = async (accessToken, provider) => {
    const response = await fetch(
      'https://api.tktchurch.com/v1/auth/unlink-provider',
      {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ provider })
      }
    );

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

    return response.status === 200;
  };

  // Usage
  try {
    await unlinkProvider(
      'eyJhbGciOiJIUzI1NiIs...', // access token
      'google' // provider to unlink
    );
    console.log('Provider unlinked successfully');
  } catch (error) {
    console.error('Failed to unlink provider:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func unlinkProvider(accessToken: String, provider: String) async throws {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/auth/unlink-provider")!)
      urlRequest.httpMethod = "POST"
      urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
      urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
      
      let body = ["provider": provider]
      urlRequest.httpBody = try JSONEncoder().encode(body)
      
      let (_, response) = try await URLSession.shared.data(for: urlRequest)
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      if httpResponse.statusCode != 200 {
          throw URLError(.badServerResponse)
      }
  }

  // Usage
  do {
      try await unlinkProvider(
          accessToken: "eyJhbGciOiJIUzI1NiIs...",
          provider: "google"
      )
      print("Provider unlinked successfully")
  } catch {
      print("Failed to unlink provider: \(error.localizedDescription)")
  }
  ```

  ```kotlin Kotlin theme={null}
  class UserService(private val client: OkHttpClient) {
      suspend fun unlinkProvider(accessToken: String, provider: String) {
          val requestBody = """
              {
                  "provider": "$provider"
              }
          """.trimIndent()

          val request = Request.Builder()
              .url("https://api.tktchurch.com/v1/auth/unlink-provider")
              .post(RequestBody.create(MediaType.parse("application/json"), requestBody))
              .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 unlink provider")
              }
          }
      }
  }

  // Usage
  try {
      userService.unlinkProvider(
          "eyJhbGciOiJIUzI1NiIs...", // access token
          "google" // provider to unlink
      )
      println("Provider unlinked successfully")
  } catch (e: Exception) {
      println("Failed to unlink provider: ${e.message}")
  }
  ```

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

  type Provider = 'google' | 'facebook' | 'apple';

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

  // Usage
  try {
    await unlinkProvider(
      'eyJhbGciOiJIUzI1NiIs...', // access token
      'google' // provider to unlink
    );
    console.log('Provider unlinked successfully');
  } catch (error) {
    console.error('Failed to unlink provider:', error.message);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": {
      "status": 400,
      "reason": "Cannot remove last authentication method"
    }
  }
  ```

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