What Is a Session?
A session represents a recently verified user. It contains two pieces of information:socketfiAccessToken is a signed JSON Web Token (JWT). It encodes the user’s identity and wallet association, and it is cryptographically signed by SocketFi so your backend can verify it without making an additional network call to SocketFi’s servers.
Using the Access Token
Attach the access token to every request your application makes to your own backend. Use the standardAuthorization: Bearer header:
@socketfi/server, and extracts the user identity and wallet address. See Backend Verification for the complete server-side flow.
Session Storage
Where you store the session depends on your platform.- React (Web)
- React Native
For web applications,
localStorage works well for persisting the token across page reloads. Pair it with React state for in-memory access during the session.localStorage is accessible to JavaScript on the same origin. If your application has a Content Security Policy and is not susceptible to XSS, this is an acceptable trade-off for usability. For higher-security applications, consider storing the token in an httpOnly cookie set by your own backend.React Context Example
For most React applications, a Context provider is the cleanest way to share session state across your component tree.Session Expiration
Sessions are intentionally short-lived. When asocketfiAccessToken expires, your backend will return an HTTP 401 response to requests that include it. Design your application to handle this without disrupting the user experience:
Sessions vs. Wallets
It is important to understand that sessions and wallets are completely independent.Common Session Errors
Security Best Practices
- Always verify tokens server-side. Frontend session state tells you who the user claims to be. The
verifyAuth()call tells you who they actually are. - Use HTTPS exclusively. Session tokens transmitted over plain HTTP can be intercepted. All production traffic must be encrypted.
- Store minimal data. Persist only the token and the user profile. Do not store wallet addresses, balance data, or other wallet state in session storage.
- Handle expiration gracefully. Build automatic re-authentication into your data-fetching layer so users are not unexpectedly locked out.