authenticate() call covers both new user registration and returning user sign-in; the SDK detects which flow to run automatically.
This guide covers the full authentication lifecycle: passkey registration vs. sign-in, session storage, backend token verification, protected routes, session expiration, re-authentication, and logout.
How authentication works
When you callsocketfi.authenticate(), the SDK opens the SocketFi hosted authentication flow. For a new user, the flow creates a passkey on their device and provisions a smart wallet on Stellar. For a returning user, the flow prompts for their existing passkey and creates a fresh session. In both cases, your app receives a Session object containing an access token and wallet information.
Authentication proves identity — it does not authorize individual transactions. Every state-changing contract call goes through a separate approval step when you call
requestTransaction().Calling authenticate()
The call signature is the same for both registration and sign-in:Session object looks like this:
Session storage and management
After authentication succeeds, persist the session so users stay logged in across page reloads or app restarts.- React (web)
- React Native
Store the session in
localStorage and rehydrate it on mount:src/auth/provider.tsx
Backend token verification
Never rely on client-side session state to grant access to backend resources. Always verifysocketfiAccessToken server-side using the @socketfi/server package.
verifyAuth() function validates the token signature and returns the verified user and wallet:
Express middleware example
src/server/middleware/requireAuth.ts
src/server/routes/wallet.ts
Protected routes
React (web)
Wrap sensitive routes in a guard component that redirects unauthenticated users to your login page:src/components/ProtectedRoute.tsx
React Native
Use a navigator that conditionally renders the authenticated or unauthenticated stack:src/navigation/RootNavigator.tsx
Handling session expiration and re-authentication
Sessions expire after a period of inactivity. When an API call returns401, catch it and trigger re-authentication:
src/api/client.ts
Logout
Logout removes the local session state. It does not delete the user’s wallet, revoke the passkey, or affect any on-chain assets.- React (web)
- React Native
Error handling for auth failures
Wrap everyauthenticate() call in try/catch. The most common errors are:
src/socketfi/client.ts
Production checklist
- ✅ Verify
socketfiAccessTokenserver-side with@socketfi/serverbefore granting API access - ✅ Store tokens in encrypted storage (
expo-secure-storeon mobile,sessionStoragefor stricter web security) - ✅ Handle session expiration and re-authenticate transparently
- ✅ Protect all sensitive routes with an auth guard
- ✅ Show loading indicators during the passkey prompt and session restore
- ✅ Monitor authentication failures in your observability tool