> For the complete documentation index, see [llms.txt](https://docs.cspr.click/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cspr.click/cspr.click-sdk/integration/handling-events.md).

# Handling events

CSPR.click emits events when the SDK is ready, when the user connects or switches accounts, and when the current session ends. Your application should listen to these events to keep its own state in sync with the wallet session.

This page covers the events most applications need during integration. Check the [Events](/cspr.click-sdk/reference/events.md) page for the complete reference.

## Register event handlers

CSPR.click emits the `csprclick:loaded` browser event after the runtime has loaded and initialized. Register your SDK event handlers inside this callback so `window.csprclick` is available.

```typescript
window.addEventListener('csprclick:loaded', () => {
  window.csprclick.on('csprclick:signed_in', async (evt) => {
    console.log('csprclick:signed_in', evt);
    // Start or refresh the user session in your application.
  });

  window.csprclick.on('csprclick:switched_account', async (evt) => {
    console.log('csprclick:switched_account', evt);
    // Update your application state for the new active account.
  });

  window.csprclick.on('csprclick:signed_out', async (evt) => {
    console.log('csprclick:signed_out', evt);
    // Clear the current user session in your application.
  });

  window.csprclick.on('csprclick:disconnected', async (evt) => {
    console.log('csprclick:disconnected', evt);
    // Close the session because the connected wallet disconnected.
  });
});
```

### csprclick:signed\_in

This event is emitted when CSPR.click connects to an account. Use it to store the connected account and enable account-specific parts of your UI.

[csprclick:signed\_in](/cspr.click-sdk/reference/events.md#csprclick-signed_in) reference.

### csprclick:switched\_account

This event is emitted when the user switches to a different account in the same wallet or another wallet. Use it to replace the current account in your application state.

[csprclick:switched\_account](/cspr.click-sdk/reference/events.md#csprclick-switched_account) reference.

### csprclick:signed\_out

This event is emitted after the application calls the `signOut()` SDK method. Use it to clear session state while leaving the wallet connection available for future sign-ins.

[csprclick:signed\_out](/cspr.click-sdk/reference/events.md#csprclick-signed_out) reference.

### csprclick:disconnected

This event is emitted when CSPR.click receives a disconnect request or event from the connected wallet. The application should close the current session as a consequence of this event.

It receives in the event object the provider that has been disconnected.

[csprclick:disconnected](/cspr.click-sdk/reference/events.md#csprclick-disconnected) reference.
