API Reference
clearUserSession()
The explicit half of Flux's multi-tenant safety model. Tears down every piece of the current user's private state — cache, queue, jobs, sync anchors, conflicts — across every open tab, while leaving public data completely untouched.
Prerequisites
- At least one store registered with scope: 'user' — see api/register
- core-concepts/multi-tenant-scoping for the full three-layer isolation model this API is part of
1
Basic usage
Call this from your logout handler, and ideally also from an auth-state-change listener — a silently expired session should be cleaned up just as thoroughly as an explicit logout click.
typescript
2
What's cleared, what isn't
Only
'user'-scoped data is touched. 'global'-scoped stores — pricing, homepage, docs, anything public — are completely untouched and survive exactly as before.typescript
3
The full purge routine
Ten steps run in a fixed order internally. This is what makes the call thorough rather than a single best-guess cache wipe.
typescript
4
Cross-tab propagation
A logout in one tab doesn't leave a second open tab holding onto the old session — the purge gossips itself to every sibling tab automatically.
typescript
5
Why in-flight requests can't resurrect purged data
This is the part that makes the purge a real guarantee rather than a race with whatever network call happened to be in flight when the user logged out.
typescript
Two independent safety nets
The abort and the generation barrier are deliberately redundant — if the abort signal somehow doesn't land in time, the generation check catches it anyway. See core-concepts/multi-tenant-scoping for the full explanation of both primitives.
6
Safe to call unconditionally
You don't need to check whether a session is active first — calling this with no user logged in is a harmless no-op.
typescript
7
Reading session state after clearing
flux.currentUserId is set to null as the second-to-last step of the purge. useFlux() mirrors it directly for components that need to react to session start/end.typescript
For the structural namespacing layer this purge sits on top of, and the boot-time sweep that catches sessions that never call this at all, see core-concepts/multi-tenant-scoping. For the conflicts this purge filters out of the register, see api/get-active-conflicts.