jackwener/OpenCLI · error · CommandExecutionError

Xiaoe admin page rendered but no user_id cookie extractable

Error message

Xiaoe admin page rendered but no user_id cookie extractable — stale session

What it means

The page rendered as authenticated (not a login UI) but neither the XIAOEID nor the unionid cookie yielded a user_id value. Since the library cannot identify the account, it throws CommandExecutionError describing a stale/partial session rather than returning empty identity.

Source

Thrown at clis/xiaoe/auth.js:37

  const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });
  const xiaoeId = cookies.find(c => c.name === 'XIAOEID')?.value || '';
  const unionId = cookies.find(c => c.name === 'unionid')?.value || '';
  const probe = await page.evaluate(`
    (() => {
      const bodyText = document.body?.innerText || '';
      if (/微信扫码登录|手机号登录|登录小鹅通/.test(bodyText)) {
        return { isLoginPage: true };
      }
      const nick = document.querySelector('.user-name, .nickname, [class*="userName"], [class*="user-info"]')?.innerText?.trim() || '';
      return { isLoginPage: false, domNick: nick };
    })()
  `);
  if (probe.isLoginPage) {
    throw new AuthRequiredError('xiaoe-tech.com', 'Xiaoe admin page showed login UI — anonymous session');
  }
  const userId = xiaoeId || unionId;
  if (!userId) {
    throw new CommandExecutionError('Xiaoe admin page rendered but no user_id cookie extractable — stale session');
  }
  return { user_id: String(userId), nickname: String(probe.domNick || '') };
}

registerSiteAuthCommands({
  site: 'xiaoe',
  domain: 'xiaoe-tech.com',
  loginUrl: 'https://admin.xiaoe-tech.com/',
  columns: ['user_id', 'nickname'],
  quickCheck: hasXiaoeAdminCookie,
  verify: verifyXiaoeIdentity,
  poll: async (page) => {
    if (!await hasXiaoeAdminCookie(page)) {
      throw new AuthRequiredError('xiaoe-tech.com', 'Waiting for Xiaoe XIAOEID/b_user_token cookie');
    }
    return verifyXiaoeIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log out and log in again via the xiaoe login flow so all identity cookies are reissued.
  2. Dump page.getCookies({url:'https://admin.xiaoe-tech.com'}) and check which cookie now carries the user id.
  3. Update the cookie names in auth.js (XIAOEID / unionid) if Xiaoe renamed them.
  4. Fall back to scraping the user id from the rendered account page DOM if cookies are unavailable.

Example fix

// before
const xiaoeId = cookies.find(c => c.name === 'XIAOEID')?.value || '';
// after
const xiaoeId = cookies.find(c => c.name === 'XIAOEID' || c.name === 'xet-user-id')?.value || ''; // include renamed cookie
Defensive patterns

Strategy: fallback

Validate before calling

const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });
const userId = cookies.find(c => c.name === 'XIAOEID')?.value || cookies.find(c => c.name === 'unionid')?.value;
if (!userId) await refreshXiaoeSession();

Type guard

function hasUserIdCookie(cs) {
  return ['XIAOEID', 'unionid'].some(n => !!cs.find(c => c.name === n)?.value);
}

Try / catch

try {
  identity = await verifyXiaoeIdentity(page);
} catch (e) {
  if (/no user_id cookie/.test(e.message)) {
    await runXiaoeLogin(page);
    identity = await verifyXiaoeIdentity(page);
  } else throw e;
}

Prevention

When it happens

Trigger: verifyXiaoeIdentity reaches the final identity extraction with xiaoeId and unionId both empty strings — cookies.find(...) returned undefined or empty values for XIAOEID and unionid on admin.xiaoe-tech.com.

Common situations: Xiaoe renamed cookies (e.g. new SSO cookie names) so XIAOEID/unionid no longer exist; b_user_token present enough to pass quickCheck but identity cookies missing; domain-scoped cookies on a subdomain not returned for the queried URL.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f20fe34a9b951d74. Report an issue: GitHub.