Project structure
Your authentication module lives undersrc/auth/. Keep the SocketFi client in its own file so it’s instantiated exactly once and imported wherever you need it.
Installation
Step-by-step files
Wire everything together
Wrap your app in<AuthProvider> at the root so every component can call useAuth().
src/main.tsx
src/App.tsx
Authentication flow
Session persistence flow
Accessing wallet info
After authentication, the wallet address is available anywhere inside<AuthProvider>:
Sending the token to your backend
AttachsocketfiAccessToken as a Bearer token on every authenticated API request:
Backend token verification
Your Express (or other) server verifies the token with@socketfi/server before trusting any request. See the Server Verification example for a complete implementation.
Logout flow
Production checklist
Session security
Store sessions in
localStorage for web or secure device storage for mobile. Never store tokens in memory-only state.Error handling
Catch
USER_CANCELLED separately and don’t show it as an error. All other failures should surface a retry prompt.Token verification
Every protected backend endpoint must call
verifyAuth() — never rely on client-provided identity claims.HTTPS
WebAuthn / passkeys require a secure context. HTTPS is mandatory in production.