@fkn/lib/account
Type Aliases
Section titled “Type Aliases”AccountInfo
Section titled “AccountInfo”type AccountInfo = object;Properties
Section titled “Properties”image: string | null;profile image URL, or null if none is set
name: string;the account’s display name (a username, not necessarily a real name)
premium
Section titled “premium”premium: boolean;the account has an active paid subscription
premiumUntil
Section titled “premiumUntil”premiumUntil: number | null;when the current subscription lapses, as a ms epoch, or null when not subscribed
Functions
Section titled “Functions”info()
Section titled “info()”function info(): Promise<AccountInfo | null>;Returns
Section titled “Returns”Promise<AccountInfo | null>
login()
Section titled “login()”function login(): Promise<boolean>;Returns
Section titled “Returns”Promise<boolean>
logout()
Section titled “logout()”function logout(): Promise<void>;Returns
Section titled “Returns”Promise<void>
onChange()
Section titled “onChange()”function onChange(callback): Promise<() => void>;Calls callback whenever the account this page acts as may have changed (a switch, a sign-in or a
sign-out, in this tab or another), and when the connection is renewed without one. Works in a window
and in a worker bridged with relayWorker; resolves to a no-op where there is no FKN transport at all.
change.switched says which. True: this page may now act as another account, or as none, so drop
what the old account put in memory (its lists, any open work) and read again; a storage call made
before this callback never lands in the new account (it is refused with StorageAccountChangedError).
It is also true when fkn.app is too old to tell (before 2026-10-02) and when the library moved on its
own after a refusal, so treating true as a switch is always safe. False: fkn.app saw the same account.
Its connect token was renewed, or an app in this browser signed in or out of FKN on its own, this one
included, so read info() again to learn whether this page is still signed in. Calls made before it
still land. A switch fkn.app could not see, because its document was replaced in between, reaches you
as true once a storage call is refused for it.
Storage moves to the new account BEFORE any callback runs. Work the app started before a switch and
resumes after it is the app’s to check: keep a counter this callback bumps when switched is true,
and compare it synchronously right before the storage call, which captures the account in the same
synchronous step, so the check and the call are atomic.
Parameters
Section titled “Parameters”callback
Section titled “callback”(change) => void
Returns
Section titled “Returns”Promise<() => void>
References
Section titled “References”AccountChange
Section titled “AccountChange”Re-exports AccountChange