For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

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

Last updated