Session Management
Comprehensive guide to managing authentication sessions in Capsule
Overview
Capsule provides a comprehensive set of methods for managing authentication sessions. These sessions are crucial for secure transaction signing and other authenticated operations. Proper session management helps maintain security while ensuring a seamless user experience.
Checking Session Status
Use isSessionActive()
to verify whether a user’s session is currently valid before performing authenticated
operations.
This method returns a boolean indicating if the session is currently valid and active. For external wallet connections, this will always return true.
Example usage:
Maintaining Active Sessions
Use keepSessionAlive()
to extend an active session’s validity without requiring full reauthentication.
This is a lightweight method that attempts to maintain the current session and returns a boolean indicating success or failure.
Example usage:
Refreshing Expired Sessions
Use refreshSession()
when a session has fully expired and needs to be reestablished through user authentication.
When shouldOpenPopup
is true, this method automatically opens an authentication window. Otherwise, it returns a URL
that should be opened in a popup for user authentication. After calling refreshSession()
, you must use
waitForLoginAndSetup()
to wait for the authentication to complete.
Pass the popup window reference to waitForLoginAndSetup()
when handling popups manually. This enables automatic
error detection if the user closes the popup.
Example usage:
Client-Server Session Transfer
Exporting Sessions
Use exportSession()
when you need to transfer session state to a server for performing operations on behalf of the
user.
Returns a Base64 encoded string containing the session state, including user details, wallet information, and authentication data.
Example client-side export:
Importing Sessions
Use importSession()
on your server to restore a previously exported session state.
exportSession()
and restores the complete session state.Example server-side implementation:
Was this page helpful?