Skip to content

Visitor, User, and Account Identity

A visitor is not yet signed in. A user is a person identified by your application’s stable internal ID. An account is the organization or billing scope that person belongs to. These identifiers are different: use user.id for the person and account_id for their current account. An account ID is not a replacement user ID, and a Stripe payer may map to an account separately.

There is no anonymous mode. A Playbook can only be evaluated against a UserContext, and a signed-out visitor has none, so user with a non-empty id is required at every entry point and in every runtime mode. Initialize the SDK after sign-in: mount RevTurbineProvider inside your authenticated tree, and show the signed-out visitor your own standard UI. RevTurbine is additive, so nothing breaks without it.

A missing user is an error. If an init does reach the SDK without a usable id (an omitted or null user, a null, omitted, blank or whitespace id), the SDK never throws into your app. It stays disabled: no network request, no evaluation, no user-scoped storage; every check and placement answers with its fallback (user_id_required); a Gate behaves as it does for a denied user (its deniedFallback, placement or placeholder, and onDenied); it logs one user_id_required console error; and it reports one typed diagnostic (getUserRequiredDiagnostic()). Do not use a blank string or null as your loading state. A later identify(id) with a real id enables the SDK.

When the user is resolved asynchronously (a session lookup, say), pass a Promise as user (0.16.0) instead:

React
import { useMemo, type ReactNode } from 'react';
import { RevTurbineProvider } from '@revturbine/sdk';
declare function fetchSessionUser(): Promise<{ id: string; plan_handle?: string }>;
export function Providers({ children }: { children: ReactNode }) {
const options = useMemo(
() => ({ publicKey: 'rtk_…', user: fetchSessionUser() }), // stable: memoise it
[],
);
return <RevTurbineProvider options={options}>{children}</RevTurbineProvider>;
}

While the promise is pending the SDK is disabled without console output or a diagnostic: no request, no evaluation, no storage, no Playbook fetch; a Gate renders nothing (not its deniedFallback); events are dropped, not buffered. When it resolves to a user ({ id, ...identify context }), the SDK behaves exactly as identify() with that user: the Playbook loads, mounted gates re-evaluate without a remount, and the first page_view is sent. If it resolves to a missing or blank id, or rejects, you get the loud user_id_required error (a rejection’s reason is in the message) and the SDK stays disabled. An explicit identify() while it is pending wins, and a result that arrives after the provider unmounted is ignored. A new promise identity re-initialises the SDK exactly as a new user object does, so keep it stable.

Before 0.13.0 the SDK fell back to a random per-browser anonymous id for a visitor with no user. That id and every fallback to it are gone, so state it held (dismissals, caps) is not carried into the identified user’s scope; it starts fresh the first time that user is initialized.

Resolve the authenticated user’s ID and authoritative account/plan before granting paid access. Use identify when the identity changes, and update for changing facts about the same user. Use a stable internal ID, never an email address; email can change and is personal data.

Switching from one identified user to a different identified user clears the previous user’s context, usage, trial state, and application-provider snapshot before applying the new user’s facts. Do not rely on a user switch to load facts your application has not supplied.

For sign-out, call the SDK’s resetIdentity() (or unmount the provider) and clear your application’s own authenticated state. After resetIdentity() the SDK has no user and is disabled until the next identify(). Clear private application caches and cancel in-flight user work as part of your app’s logout; the SDK cannot clear application state it does not own.

The same person may switch accounts without changing their user ID. Refresh the complete account-scoped context from your trusted backend, including plan, usage, add-ons, and mirrored grants. Explicitly clear obsolete values rather than merging a new account ID onto the old account’s entitlements. On a server, construct a fresh session for the selected user/account operation.

An account membership check belongs to your application. A context token should be issued only after that check; never sign an arbitrary client-provided account_id or plan. See cloud enforcement.

Start signed out (no SDK), sign in as a paid user, sign out, then sign in as a free user without reloading the application. Assert the actual SDK context and gate result after every transition. Repeat with one user switching accounts. The free user must not retain the paid user’s grants or balances.