Multi Tenant Session Scoping
A shared browser, such as a family computer, a work kiosk, or a laptop passed between roommates, can have two different people log into the same app minutes apart. Without an explicit boundary, one person's cached dashboard, queued edits, or in progress uploads can still be sitting there when the next person logs in. Scoping is how Flux draws that boundary, and keeps it intact even when a logout never happens cleanly. Encryption at rest makes that boundary hold on disk as well.
A clean logout button is easy to build and easy to rely on, until a tab crashes, a laptop lid closes mid session, or an auth cookie silently expires with no logout event ever firing. Any of those leaves cached data belonging to person A still sitting in the browser when person B opens the same app. A caching layer that only clears itself when explicitly told to has a gap exactly where it matters most.
Flux closes that gap with independent safeguards rather than one: structural isolation, an explicit teardown call, a self healing check at the next session start, and encryption at rest, so that even if one of them is skipped entirely, the others still catch it.
Every store declares who it belongs to
scope, either 'global' (the default) for data that is the same for everyone and safe to keep indefinitely, or 'user' for data that belongs to one signed in person specifically: a dashboard, a billing panel, a private queue of edits. A 'user' scoped channel is physically kept apart from every other user's copy of that same channel, so one account's data is never reachable under another account's identity, even by accident.A single call tears down everything private
flux.clearUserSession() from your logout handler resets every 'user' scoped store back to empty, cancels any of that user's writes or fetches still in flight, stops tracking their in progress jobs, clears any conflict prompts waiting on their decision, and clears their cached data, all in one call. Public, 'global' scoped data is left completely untouched, since it never belonged to any one person in the first place.Logging out in one tab clears the session in every other tab open to the same app on that browser, not just the tab where the button was clicked. A second tab left open in the background never keeps holding a signed out user's data in memory.
A self healing check for the logout that never happened
Encryption at rest for user scoped data
encryption block to createFlux() and every 'user' scoped cache entry and every 'user' scoped queued write is sealed with AES GCM before it reaches IndexedDB. The key is derived per user from a secret your own backend issues, so it never lives in your code, and an unlocked key stays on the device only for as long as the idle window allows.| Data | Scope | What is on disk |
|---|---|---|
| Cache entries | 'user' | Ciphertext, bound to its key, timestamp and TTL |
| Cache entries | 'global' | Readable data plus a checksum. Detects edits, not a security boundary. |
| Queued writes | 'user' | Readable header with the user id, encrypted body |
| Queued writes | 'global' | Readable body plus a checksum, userId is null |
The same scope field that namespaces a channel also decides whether its data is encrypted and which queue it belongs to. That is why a queued write needs both 'user' and a real user id: with either missing, Flux stores it as a global record that a signed in user's replay never picks up. See Steps 17 to 20 of the Next.js and React getting started guides for the full key route and queue setup.
The first time a user unlocks on a device, Flux must reach your key route. After that the unlocked key is kept on the device, so offline cold starts keep working. A device that signs in for the first time while offline stays locked, and queued user writes are refused with FluxLockedError rather than stored as plaintext.
Two ways to sign out, and what happens to tampered data
| Situation | What Flux does |
|---|---|
| Signed out user's sealed writes | Stay on disk and replay at that user's next sign in. |
| Sealed writes of a user who never returns | Deleted after queueRetentionMs (default 30 days). |
| Another user signs in on the same device | Cannot read the first user's sealed writes and never replays them. |
| Stored record edited outside the app | Fails verification and is removed. Reported to your integrity listener. |
scope is optional and defaults to 'global', so registrations written before this existed keep working unchanged. In development, Flux will point out, with a console warning only and never a blocking error, if a channel name that sounds private (dashboard, billing, account, and similar) was left on the public default, so a private looking store does not quietly go unscoped by accident.Multi tenant scoping is not a paid feature. Every tier, including Free, gets the same isolation and cleanup guarantees. An app with authenticated dashboards is expected to need this correctly, regardless of what it is paying for. It is treated as a baseline correctness guarantee, not something to upsell.
For the field itself, see api/register and api/clear_user_session. For how scoping interacts with the offline queue and job tracker specifically, see core_concepts/offline_queue and core_concepts/job_tracker. For the key route and its environment variables, see guides/encryption_key_route.