diff --git a/_sidebar.md b/_sidebar.md index 6e4d84d..a4f7702 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -6,6 +6,7 @@ * [isAllowed](extension/playground/isAllowed.md) * [setAllowed](extension/playground/setAllowed.md) * [requestAccess](extension/playground/requestAccess.md) +* [disconnect](extension/playground/disconnect.md) * [getAddress](extension/playground/getAddress.md) * [getNetwork](extension/playground/getNetwork.md) * [getNetworkDetails](extension/playground/getNetworkDetails.md) diff --git a/extension/connecting.md b/extension/connecting.md index fa69097..ecb9697 100644 --- a/extension/connecting.md +++ b/extension/connecting.md @@ -1,6 +1,6 @@ # Connecting to Freighter -Detect whether a user has Freighter installed, check if your app is authorized, and request access to the user's public key. +Detect whether a user has Freighter installed, check if your app is authorized, request access to the user's public key, and disconnect. ## Detecting Freighter @@ -96,6 +96,32 @@ if (accessResult.error) { Always check `isConnected()` before calling `requestAccess()` to ensure the extension is available. {% endhint %} +## Disconnecting + +### `disconnect()` + +Revoke your app's access to the user's public key, for example from a "Disconnect" button in your app. Freighter removes your app from the Allow List without asking the user to confirm, so the next call to `requestAccess()` or `setAllowed()` prompts the user again. + +**Returns:** `Promise<{ error?: FreighterApiError }>` + +```typescript +import { disconnect } from "@stellar/freighter-api"; + +const result = await disconnect(); + +if (result.error) { + console.error("Disconnect failed:", result.error.message); +} else { + console.log("App removed from Allow List"); +} +``` + +Calling `disconnect()` when your app isn't on the Allow List succeeds without changing anything. It returns an error if the user hasn't unlocked Freighter since the browser started, or if the installed version of Freighter doesn't support `disconnect()`. + +{% hint style="warning" %} +Freighter authorizes apps per account and per network, and `disconnect()` only revokes access for the account and network that are active when you call it. If the user previously authorized your app on another account or network, your app will have access to that public key again, without a prompt, when the user switches to it. +{% endhint %} + ## Next steps Once connected, you can [read the user's address and network](reading-data.md) or [sign transactions](signing.md). diff --git a/extension/playground/disconnect.md b/extension/playground/disconnect.md new file mode 100644 index 0000000..0322717 --- /dev/null +++ b/extension/playground/disconnect.md @@ -0,0 +1,37 @@ +# disconnect + +`disconnect()` + +Test Freighter's `disconnect` method: + +**Remove this app from Freighter's Allow List for the active account and network.** + + + +