LFUser
Global:LFUser · Enable:// @require user
Reads the plugin login state and the current user's info. Serves cached values when possible, with at most one background round-trip. Available in every execution environment: enabled/installed apps (including background apps), liveDebug, run --tab (MAIN-world scripts go through an ISOLATED-world relay bridge the editor installs automatically), run --target background, and run without --tab.
Methods
LFUser.isLoggedIn(options?): Promise<boolean>Whether the plugin is logged in ({ force: true } refreshes)
LFUser.getUserInfo(options?): Promise<UserInfo | null>Current userInfo (nickname, account …); null when logged out
LFUser.getContext(options?): Promise<UserContext>Combined login state + userInfo context
LFUser.refresh(): Promise<UserContext>Forces a refresh and returns the latest context
Parameters and returns
isLoggedIn / getUserInfo / getContext all accept an optional { force?: boolean } (default false): pass true to bypass the in-memory cache and re-query the background. The cache belongs to the current running instance; it never expires on its own and is not invalidated by login changes — after the user logs in/out elsewhere, call refresh() (or pass force: true) to rebuild it.
An unreachable backend or a non-2xx response also resolves as logged out (isLoggedIn() is false, getUserInfo() is null) instead of rejecting; the methods reject only when no messaging channel is available or the server's user info lacks a user ID.
UserInfo fields
Guaranteed fields (when getUserInfo() is non-null):
| Field | Type | Description |
|---|---|---|
userId | string | User id (always present) |
username | string / undefined | Account name; WeChat accounts without a linked phone may use a placeholder such as u-xxxxxxxxxx |
nickname | string / undefined | Nickname (may be an empty string) |
isAdmin | boolean | Whether the account is an administrator (from the server's is_admin) |
accountKey | string | Account isolation key; equals userId |
Optional extensions: may change with the server or be absent. Check for null or undefined before use.
| Field | Type | Description |
|---|---|---|
phone | string / undefined | Linked phone number, empty when unlinked; use this field to display a phone number |
isCreator | boolean / undefined | Whether the account is a creator (from the server's is_creator) |
avatarUrl | string / undefined | Avatar URL from avatar_url; empty string when no avatar is set |
add_date | string / undefined | Signup time, YYYY-MM-DD HH:mm:ss; passed through from the server |
last_login_at | string / undefined | Last login time, same format; passed through from the server |
Raw fields such as id / user_id / is_admin / is_creator / avatar_url are also optional extensions. No email, tenant or balance fields are provided; query credits with LFModel.getBalance().
getContext() / refresh() resolve to { loggedIn: boolean, userInfo: UserInfo | null, baseUrl: string }, where baseUrl is the server base URL (no trailing slash) — app code rarely needs it.
Example
// @require user
if (await LFUser.isLoggedIn()) {
const userInfo = await LFUser.getUserInfo();
LFRuntime.print(userInfo?.nickname || userInfo?.username);
} else {
LFRuntime.print("Not signed in to the extension");
}