browser
For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.
Framework-agnostic browser building blocks for Convex Auth clients: a token
storage abstraction, a cross-tab refresh mutex, and the session manager that
ties them together. The React bindings (@convex-dev/auth/react) build on
these, and other client libraries can too.
Classes
Interfaces
Type Aliases
AuthClientConfig
type AuthClientConfig =
| (AuthClientConfigBase & object)
| (AuthClientConfigBase & object);
Configuration for the AuthClient, discriminated by
session mode.
The mode determines who holds the refresh token, and therefore the shape of the auth API the client drives:
"spa": JS holds the refresh token; the client passes it to a SpaAuthApi."ssr": the refresh token is in an httpOnly cookie; a SsrAuthApi is called without one and reads the cookie server-side.
Variables
JWT_STORAGE_KEY
const JWT_STORAGE_KEY: "__convexAuthJWT" = "__convexAuthJWT";
Storage key for the current access token (a JWT).
REFRESH_TOKEN_STORAGE_KEY
const REFRESH_TOKEN_STORAGE_KEY: "__convexAuthRefreshToken" =
"__convexAuthRefreshToken";
Storage key for the current (rotating) refresh token.
Functions
defaultStorage()
function defaultStorage(): TokenStorage;
The default storage: the browser's localStorage when available, otherwise an
InMemoryStorage. Callers that need cross-tab
sessions, React Native, or per-tab sessions should pass their own storage
instead.
Returns
runWithMutex()
function runWithMutex<T>(key, callback): Promise<T>;
Run callback while holding the lock named key, resolving to its result. Only
one callback per key runs at a time.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
key | string |
callback | () => Promise<T> |
Returns
Promise<T>
References
TokenStorage
Re-exports TokenStorage