Creates a new UserTokenStore instance.
Optionalstorage: TokenStorageAdapter
Optional custom storage adapter conforming to TokenStorageAdapter.
Indicates whether this store instance is backed by a persistent storage adapter.
When false, user tokens and changelog seen sets exist in memory only
and will not survive application restarts. Call UserTokenStore.configure
or provide a custom TokenStorageAdapter to the constructor to enable
durable cross-session persistence.
Synchronously returns the currently cached user token. If not already initialized, generates and caches a new in-memory UUID.
Warning — async storage adapters: with AsyncStorage / SecureStore the
persisted token loads asynchronously, and accessing .token before that
load finishes mints and caches a throwaway in-memory UUID that is never
persisted and will be replaced once storage resolves. Any request sent in
that window is attributed to the throwaway identity. With async adapters
always await UserTokenStore.getToken instead (the SDK's
<CupThreadProvider> does this for you and exposes readiness through
useCupThreadTokenReadiness()). The synchronous contract is only safe for
synchronous adapters or no-adapter setups.
Explicit identities installed during the async load window via UserTokenStore.setToken or UserTokenStore.resetToken are authoritative and are never reverted by any storage re-read (the initial load or a later UserTokenStore.getToken).
StaticsharedReturns the shared singleton instance of UserTokenStore.
Asynchronously retrieves the user token, prioritizing recovery of existing tokens from storage.
A promise resolving to the user token string.
If storage already contains a token, it is restored into memory and returned. A new UUID is generated and persisted only when storage is verified to be empty.
Explicit identities installed via UserTokenStore.setToken or
UserTokenStore.resetToken are authoritative: getToken() never
re-reads storage past one, and a storage read that was already in flight
when the explicit identity was installed cannot revert it either. This
also holds when the explicit identity's own persistence write failed
(storage keeps an older token while the cache holds the explicit one).
Checks whether a changelog release version or entry ID has already been marked as seen.
Changelog version label (e.g. '1.2.0') or entry ID.
Promise resolving to true if seen, false otherwise.
Resets the active user token and generates a brand new UUID in memory and storage.
The newly generated user token.
Like UserTokenStore.setToken, the reset is authoritative: neither an in-flight initial storage read nor a later UserTokenStore.getToken re-read (async adapters) can overwrite the cache or revert the identity.
Resets the dev warning flag for test environments.
Overrides the current user token with an explicit identifier (e.g. from your auth service).
Custom user identifier or token string.
The explicit token is authoritative: neither the constructor's initial
storage read nor any later UserTokenStore.getToken re-read (async
adapters) can overwrite the cache or revert the identity — including
reads that were already in flight when setToken() was called, and
including after a failed persistence write (storage may keep an older
token; the in-memory identity still wins).
Subscribes a listener that is notified whenever the active identity changes.
Callback invoked with no arguments on identity changes.
An unsubscribe function; safe to call multiple times.
Listeners fire after UserTokenStore.setToken, UserTokenStore.resetToken,
or an identity-changing UserTokenStore.getToken resolution completes
(memory and storage both settled). Reactive consumers such as
<CupThreadProvider> use this to follow documented login/logout flows.
Emits a one-time console warning in development mode if the store is not backed by a persistent storage adapter when changelog seen-status is inspected or marked.
StaticconfigureReconfigures the shared singleton with a custom storage adapter.
Storage adapter instance.
The configured singleton UserTokenStore.
StaticresetResets the shared singleton instance for test isolation.
Manages device-level persistent anonymous user tokens for CupThread SDK interactions.
Remarks
Anonymous tokens allow users to submit feedback, upvote roadmap features, and participate in discussions without requiring an upfront sign-in. The token is generated as an RFC 4122 v4 UUID and can be stored across app restarts using custom storage adapters (e.g. AsyncStorage / SecureStore).
Example