Skip to main content
Authentication in SocketFi is handled through a single method: 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

Calling authenticate() 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.
The SDK handles sign-in and sign-up through the same authenticate() call — you don’t need separate flows for new versus returning users.

The Session object

A successful call to authenticate() returns a session with the following shape:
Store 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 call authenticate() and receive a session. The difference is invisible to your code.
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 a logout function through a useSocketFiAuth hook.
lib/AuthProvider.tsx
Wrap your application with AuthProvider at the root:
main.tsx
Then use the hook in any component:
components/LoginButton.tsx

Protecting routes

Use isAuthenticated from the context to gate access to parts of your application:
components/ProtectedRoute.tsx

Logout

Call logout() from the context to clear the session from both React state and localStorage:
components/UserMenu.tsx

Error handling

Wrap every authenticate() call in a try/catch block and handle the error codes your users are most likely to encounter:

Error codes reference