Skip to main content
Building authentication with SocketFi means your users get a passkey-powered, seed-phrase-free login experience, and you get a fully typed session object with a wallet address and an access token ready to send to your backend. This example walks you through every file you need — from SDK initialization to protected routes — so you can drop a working auth system into any React project.

Project structure

Your authentication module lives under src/auth/. Keep the SocketFi client in its own file so it’s instantiated exactly once and imported wherever you need it.

Installation

Set your client ID in an environment variable — never hard-code it.

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

Attach socketfiAccessToken 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.
Never trust wallet addresses or user IDs sent directly from the client. Always verify the access token server-side with verifyAuth() and derive identity from the verified result.

Logout flow

Logout only clears local session state — the user’s wallet and assets are completely unaffected.

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.