FLOWDocs

Getting started

Integrate redirect sign-in and account management with first-party sessions.

Use the current @flow-industries/id SDK for hosted sign-in and first-party app sessions. Sign in and create an account covers the player-facing flow.

Install

bun add @flow-industries/id viem ox

Serve a first-party session route

Mount the SDK handler at /flow/session on your app's own server. Register your exact app origin with Flow ID. Set the public audience explicitly behind a reverse proxy.

import { handleSessionRequest } from "@flow-industries/id/server";

export function sessionRoute(request: Request) {
  return handleSessionRequest(request, {
    audience: "https://app.example",
    issuerUrl: "https://id.flow.industries",
  });
}

Route GET, POST and DELETE to this handler. It owns session cookies, login transactions and the authorization callback. GET restores the session or completes a callback; POST starts login, installs authorized sessions, or starts an account handoff; DELETE signs out. Keep the handler's origin, state, PKCE and return-path validation intact.

For TanStack Start, use flowSessionHandlers() and resolveFlowSessionRequest() from @flow-industries/id/start/server, then pass the resolved session to FlowRoot from @flow-industries/id/start. Create the server function in your app so the framework keeps session resolution server-side.

Start sign-in

Initialize one browser instance:

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

const flow = createFlow();

signInButton.addEventListener("click", () => {
  void flow.login().catch(showSignInError);
});

signUpButton.addEventListener("click", () => {
  void flow.login({ signUp: true }).catch(showSignInError);
});

showSignInError is your app's visible error handler. login() navigates the current tab to Flow ID's canonical /authorize page. It returns Promise<never>: successful navigation never resumes the old document. Remove const session = await flow.login() and post-login promise continuations. Read the restored session after the app loads again.

By default the saved return path includes the current path, query and fragment. An optional returnTo must be a local absolute path, such as /rooms?view=joined#recent. Recheck room access after return and ask again before consequential actions. A game reconnects using its returned room URL because redirect sign-in unloads its runtime.

Cancellation preserves the originating app session. Guest upgrade uses server-verified proof; do not pass a user ID or guest token in a navigation URL. autoGuest: true and ensureGuest() restore or mint through the same-origin handler without an auth iframe.

React

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

function Account() {
  return <ProfileButton />;
}

ProfileButton renders in any auth state, so you don't branch on user yourself: it shows the account dropdown when signed in and a Sign in button that starts hosted sign-in when signed out. Use FlowRoot for SSR, or FlowIdProvider with your explicit browser instance. Never construct a browser-only Flow instance during server rendering.

Open your account

The Manage account action in ProfileButton opens /account in a normal new tab. The imperative API is flow.openAccount(): boolean; call it directly from a user click. A false result means the tab was blocked. Offer a normal link to your issuer’s account page (for example, https://id.flow.industries/account) with target="_blank" and rel="noopener noreferrer"; the SDK menu reports when opening the tab is blocked.

The source game or conversation remains loaded. Release pointer lock as necessary. SDK focus reconciliation refreshes the source account/profile state without silently adopting another account managed in the new tab. Direct visits and bookmarks work independently of an opener.

openProfile(username) remains the API for other players' public profiles. Own-account editing no longer uses that overlay. Signing prompts, public-profile overlays, inline widgets and Talk/Voice embeds are separate surfaces and are not removed by redirect sign-in.

Embedded callers and credentials

An embedded app asks its trusted top-level host to start login. Validate both origin and source window, send a narrow action, and let the host choose the return path and identity. Calling login() inside an iframe is rejected.

Refresh credentials remain in HttpOnly cookies; access JWTs are available through getToken(). Authorization callbacks carry only a bounded single-use code and state. Never put tokens or private signing keys in URLs, logs or messages. Email-only and guest identities may have no signing credential or wallet address; gate signing UI accordingly. See Signing and Access keys.

For SSR and the packaged profile-menu stylesheet, see the React integration. For account selection, use flow.listAccounts(), flow.switchAccounts({ userId }), or flow.addAccount(); selection is verified by Flow ID and returns through the same app callback.

On this page