Skip to main content
verifyAuth() is the core function of the @socketfi/server SDK. Call it on every incoming request that requires authentication, passing the raw token from the Authorization header. The function downloads and caches SocketFi’s public signing keys automatically, verifies the token’s cryptographic signature, validates its claims, and returns a strongly-typed result you can act on immediately — no manual JWT configuration required.

Function signature

Parameters

string
required
The raw SocketFi access token string. Extract this from the Authorization: Bearer <token> header before passing it to verifyAuth(). Do not include the Bearer prefix.

Return value

verifyAuth() returns Promise<VerifyAuthResult>. The shape of the resolved value depends on whether verification succeeded.

On success

true
required
Always true when verification succeeds.
object
required
The verified user object.
object
required
The user’s embedded Stellar smart wallet.

On failure

false
required
Always false when verification fails.
object
required
The verification error.

Extracting the token from the Authorization header

SocketFi access tokens are sent as Bearer tokens. Parse them from the Authorization header before calling verifyAuth():
Call verifyAuth() on every protected request. Never cache or reuse the result across requests — each call re-validates the token’s expiry and signature freshness.

Success example

Failure example

Complete protected route example

Error codes

The following error codes can appear in auth.error.code when auth.valid is false:
You do not need to configure signing keys, JWKS URLs, or JWT libraries. verifyAuth() handles all of that automatically. If you need to force-refresh the cached public keys (for example, during key-rotation testing), call clearKeyCache() before the next verification.