authenticate(). When a user clicks your login button, the SDK opens a hosted popup where they complete passkey sign-in or registration. Once the popup closes, you receive a session object you can store and use throughout your app.
How authentication works
Callingauthenticate() triggers the following sequence entirely inside the hosted SocketFi popup:
1
Popup opens
The SDK opens the SocketFi hosted authentication screen in a popup window.
2
User authenticates with a passkey
New users register a passkey on their device. Returning users verify their existing passkey.
3
Wallet resolved or created
For returning users, the associated smart wallet is resolved automatically. For new users, a new embedded smart wallet is created and activated.
4
Session returned
The popup closes and
authenticate() resolves with a Session object containing the user’s profile and an access token.authenticate() call — you don’t need separate flows for new versus returning users.
The Session object
A successful call toauthenticate() returns a session with the following shape:
userProfile to identify the user in your UI and keep socketfiAccessToken for any subsequent SDK calls that require an authenticated context.
Sign-in vs sign-up flow
Both flows begin and end identically from your application’s perspective — you callauthenticate() and receive a session. The difference is invisible to your code.
- Returning user (sign-in)
- New user (sign-up)
Always call
authenticate() from a direct user action such as a button click. Browsers will block the popup if it’s triggered programmatically on page load or inside a useEffect.Session management with React Context
For most applications, the best place to store the SocketFi session is a React Context that wraps your component tree. The pattern below gives any component access to the current user and alogout function through a useSocketFiAuth hook.
lib/AuthProvider.tsx
AuthProvider at the root:
main.tsx
components/LoginButton.tsx
Protecting routes
UseisAuthenticated from the context to gate access to parts of your application:
components/ProtectedRoute.tsx
Logout
Calllogout() from the context to clear the session from both React state and localStorage:
components/UserMenu.tsx
Error handling
Wrap everyauthenticate() call in a try/catch block and handle the error codes your users are most likely to encounter: