FLOWDocs
SDK

React

Share Flow state, account UI, and server-rendered sessions.

The React adapter shares the browser Flow instance with hooks and the account menu. Install the first-party session route before using login controls.

Browser apps

Initialize createFlow() once in your browser entry point. Hooks use that singleton, or you can pass an explicit instance through FlowIdProvider:

import { createFlow } from "@flow-industries/id";
import { FlowIdProvider } from "@flow-industries/id/react";

const flow = createFlow();

export function App({ children }: { children: React.ReactNode }) {
  return <FlowIdProvider flow={flow}>{children}</FlowIdProvider>;
}

This example belongs in browser-only code. createFlow() throws on the server, and constructing it during a render creates duplicate runtime ownership.

Hooks and the account menu

useFlow() returns the Flow instance. useFlowState() subscribes to its full state. useFlowId() exposes the common identity and authentication methods, including user, address, isAuthenticated, login, logout, restore, refreshJwt, and getToken.

login() navigates to hosted sign-in; it does not resolve to a completed session in the old page. Restore state after return. Guests also have isAuthenticated: true, and registered email-only users can have a null address.

Further hooks cover the rest of the SDK surface: useActiveAction() reads the caller's running action session without polling, usePresence() and usePresenceActionSession() read and set personal presence, useRoom() and useRooms() read the room registry, and useOpenProfile() opens another player's public profile. FlowWidget renders an inline Flow surface.

Render ProfileButton for the shared account dropdown. It renders in any auth state: a Sign in button when signed out, and when signed in a menu with the personal status picker (online, idle, busy, invisible), remembered-account selection, Switch account, Add account, Manage account, and sign-out. Manage account opens a normal tab directly from the click and reports a blocked popup. See Use multiple accounts.

Tailwind apps already using Flow UI should scan the SDK package:

@source "../node_modules/@flow-industries/id/dist/sdk";

Adjust the relative path for your stylesheet. Other apps can import the packaged menu styles once:

import "@flow-industries/id/profile.css";

TanStack Start

Create the session route and server function in your app source:

import { createFileRoute } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/react-start";
import {
  flowSessionHandlers,
  resolveFlowSessionRequest,
} from "@flow-industries/id/start/server";

export const getFlowSession = createServerFn({ method: "GET" }).handler(
  resolveFlowSessionRequest,
);
export const Route = createFileRoute("/flow/session")({
  server: { handlers: flowSessionHandlers() },
});

Use flowSessionContext(getFlowSession) from @flow-industries/id/start in the root route's beforeLoad. Wrap the root content in FlowRoot, passing the resolved session. It creates per-request static state for SSR and hydrates the browser without constructing a browser runtime on the server. Enable autoGuest only when the app should mint guest identities.

For other SSR frameworks, resolveSession(cookieHeader, { audience }) from @flow-industries/id/server returns { state, setCookies }. Append every setCookies entry to the response: a refresh rotates the token, so dropping those headers leaves the browser with a dead predecessor. Use per-request static state and hydrate the browser with initialState; never share one user's static session across requests.

A Wagmi integration can share the same Flow instance.

On this page