Skip to content

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 ​

ts
LFUser.isLoggedIn(options?): Promise<boolean>

Whether the plugin is logged in ({ force: true } refreshes)

ts
LFUser.getUserInfo(options?): Promise<UserInfo | null>

Current userInfo (nickname, account …); null when logged out

ts
LFUser.getContext(options?): Promise<UserContext>

Combined login state + userInfo context

ts
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):

FieldTypeDescription
userIdstringUser id (always present)
usernamestring / undefinedAccount name; WeChat accounts without a linked phone may use a placeholder such as u-xxxxxxxxxx
nicknamestring / undefinedNickname (may be an empty string)
isAdminbooleanWhether the account is an administrator (from the server's is_admin)
accountKeystringAccount isolation key; equals userId

Optional extensions: may change with the server or be absent. Check for null or undefined before use.

FieldTypeDescription
phonestring / undefinedLinked phone number, empty when unlinked; use this field to display a phone number
isCreatorboolean / undefinedWhether the account is a creator (from the server's is_creator)
avatarUrlstring / undefinedAvatar URL from avatar_url; empty string when no avatar is set
add_datestring / undefinedSignup time, YYYY-MM-DD HH:mm:ss; passed through from the server
last_login_atstring / undefinedLast 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

js
// @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");
}