createFlow
Browser session, redirect sign-in and signing API.
See Getting started for the required first-party /flow/session server handler. One browser instance serves React, Wagmi and direct callers.
import { createFlow } from "@flow-industries/id";
const flow = createFlow({
host: "https://id.flow.industries",
sessionPath: "/flow/session",
autoRestore: true,
autoGuest: false,
});host is the Flow ID service origin. sessionPath is the app's same-origin session endpoint. autoRestore restores the app session on startup; autoGuest opts into guest identity creation. SSR integrations resolve sessions server-side and hydrate with FlowRoot instead of constructing the browser client on the server.
Authentication and account navigation
flow.login({ returnTo: "/rooms?view=joined#recent" });
flow.login({ signUp: true });
flow.openAccount();
flow.logout();
flow.restore();
flow.refreshJwt();
flow.getToken();Call login() from an action and handle rejection visibly. It starts top-level document navigation; it never resolves with a completed Session in the departed document. Read flow.user or reactive state after the callback returns and the app reloads. returnTo accepts only a local absolute path. The old mode, iframe/popup sign-in and signInHeadless options are retired.
openAccount() opens a normal tab synchronously from a user gesture. false means opening was blocked; provide a normal account-page link as fallback. ProfileButton provides this behavior and reports when the new tab is blocked. The source session is rechecked on focus.
restore(), refreshJwt(), getToken() and logout use the first-party endpoint. Normal session refresh does not load an authentication iframe. getToken() refreshes a missing or expiring JWT and returns null when no usable session remains. Do not persist refresh tokens in browser storage.
Reactive state
flow.user, flow.jwt, flow.credential, flow.address and flow.isAuthenticated reflect the current state. getState() reads it and subscribe(listener) observes changes, returning an unsubscribe function. An authenticated email-only or guest identity can have a null credential/address.
getFlow() returns the current singleton, requireFlow() requires one, and resetFlow() is intended for tests. Avoid resetting a live app's instance.
Rooms, presence and AT Protocol
flow.rooms;
flow.presence.setStatus("busy");
await flow.atproto.resolve();flow.rooms is the room registry client (also exposed through useRoom/useRooms). flow.presence reads and sets personal presence; setStatus updates availability and subscribe(listener) observes it. flow.atproto.resolve() returns the signed-in account's AT Protocol identity — DID, handle and PDS origin — for an app that needs it, and flow.atproto.invalidate() drops the cached resolution. See Sign in with Bluesky.
Account selection and passkey setup
listAccounts() returns remembered-account display data; authorization remains in the app’s HttpOnly session. switchAccounts({ userId }) selects a server-verified account hint, and addAccount() starts another sign-in. Both navigate through Flow ID and return to the app. connectPasskey({ returnTo: "/", requirePrf: true }) starts account-bound setup when an app needs a passkey with PRF support; omit requirePrf when that capability is not needed.
Signing
signMessage, signTypedData, sendTransaction, sendCalls and walletClient retain their signing responsibilities. Configure chains and transports for the relevant network; accessKey configures optional delegated signing. See Signing and Access keys.
The low-level dialog surface is for retained signing operations, not sign-in, logout, guest creation or own-account management. Do not move private keys through redirect callbacks.