Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 27 additions & 1 deletion extension/connecting.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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).
37 changes: 37 additions & 0 deletions extension/playground/disconnect.md
Original file line number Diff line number Diff line change
@@ -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.**

<button class="playground-btn" id="btn-disconnect">Disconnect</button>

<div class="playground-result" id="result-disconnect">Click the button to test</div>

<script>
document.getElementById('btn-disconnect').addEventListener('click', async function() {
var el = document.getElementById('result-disconnect');
el.className = 'playground-result';
el.textContent = 'Disconnecting...';
if (typeof window.freighterApi.disconnect !== 'function') {
el.className = 'playground-result error';
el.textContent = 'Error: the loaded version of @stellar/freighter-api does not include disconnect()';
return;
}
try {
var res = await window.freighterApi.disconnect();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This is a known merge blocker. The "Before merge" section of the PR description tells it.

The version change cannot occur now. No freighter-api release on npm includes disconnect() yet. stellar/freighter#3036 adds the method. After that release is on npm, this PR will change index.html to load it.

Until then, 186562a prevents the TypeError. If the loaded freighter-api does not include disconnect(), the page now shows this error: "the loaded version of @stellar/freighter-api does not include disconnect()". This thread stays open until the version change.


Generated by Claude Code

if (res.error) {
el.className = 'playground-result error';
el.textContent = 'Error: ' + res.error.message;
} else {
el.className = 'playground-result success';
el.textContent = 'Disconnected';
}
} catch (e) {
el.className = 'playground-result error';
el.textContent = 'Error: ' + e.message;
}
});
</script>
1 change: 1 addition & 0 deletions playgrounds-home.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For docs and integration guides, see [docs.freighter.app](https://docs.freighter
| [isAllowed](extension/playground/isAllowed.md) | Check if your app is authorized |
| [setAllowed](extension/playground/setAllowed.md) | Request authorization for your app |
| [requestAccess](extension/playground/requestAccess.md) | Request the user's public key |
| [disconnect](extension/playground/disconnect.md) | Revoke your app's access |
| [getAddress](extension/playground/getAddress.md) | Get the user's wallet address |
| [getNetwork](extension/playground/getNetwork.md) | Get the active network |
| [getNetworkDetails](extension/playground/getNetworkDetails.md) | Get full network configuration |
Expand Down
Loading