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

# Disconnect

The `disconnect` method defines what happens when a connection is disconnected. Use it to revoke access tokens or perform other cleanup with the external service before credentials are erased from storage.

This method is triggered when:

* A connection is explicitly disconnected (via the API or the console UI)
* A connection is archived

This method is optional. If not implemented, the connection will simply have its credentials erased without notifying the external service.

## Implementation

**Supported implementation types**

* [Javascript](/docs/references/functions/function-types/javascript)

### JavaScript Implementation

```yaml theme={null}
# Connector definition: Revoke the access token when disconnecting
disconnect:
  type: javascript
  code: |
    export default async function disconnect({
      externalApiClient,
      credentials,
    }) {
      await externalApiClient.post('/oauth/revoke', {
        token: credentials.access_token,
      })
    }
```

## Input Parameters

| Parameter             | Description                                                                                                                          |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `connectorParameters` | Parameters configured for the connector in your workspace. Includes client IDs, secrets, and other connector-specific configuration. |
| `connectionInput`     | Input provided by the user in the connection UI when they set up the connection.                                                     |
| `credentials`         | Current credentials of the connection that will be erased after this method completes.                                               |
| `externalApiClient`   | API client for making requests to the external service (available if `makeApiClient` is defined on the connector).                   |

## Return Value

The return value is ignored. The method is expected to perform side effects only (e.g., revoking tokens).

## Error Handling

If the disconnect method throws an error, the disconnection process will still continue — credentials will be erased and the connection will be marked as disconnected. The error will be logged but will not prevent the disconnection.

This ensures that connections can always be cleanly disconnected even if the external service is unavailable.

## Supported Auth Types

The disconnect method is available for the following authentication types:

* [OAuth2](/reference/workspace-elements/connectors/connector-types/oauth2)
* [OAuth1](/reference/workspace-elements/connectors/connector-types/oauth1)
* [Client Credentials](/reference/workspace-elements/connectors/connector-types/client-credentials)
