Skip to content

@fkn/lib/account

type AccountInfo = object;
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: boolean;

the account has an active paid subscription

premiumUntil: number | null;

when the current subscription lapses, as a ms epoch, or null when not subscribed

function info(): Promise<AccountInfo | null>;

Promise<AccountInfo | null>


function login(): Promise<boolean>;

Promise<boolean>


function logout(): Promise<void>;

Promise<void>


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.

(change) => void

Promise<() => void>

Re-exports AccountChange