jackwener/OpenCLI · error · AuthRequiredError

Xianyu /personal shows login prompt — anonymous

Error message

Xianyu /personal shows login prompt — anonymous

What it means

verifyXianyuIdentity probes the logged-in goofish.com /personal page; if the page renders but shows a login prompt instead of the user profile, the session is anonymous. The library throws AuthRequiredError because identity (unb/tracknick cookies) cannot be verified without an authenticated session.

Source

Thrown at clis/xianyu/auth.js:37

  const cookies = await page.getCookies({ url: 'https://www.goofish.com' });
  const tracknick = cookies.find(c => c.name === 'tracknick')?.value || '';
  const unb = cookies.find(c => c.name === 'unb')?.value || '';
  const probe = await page.evaluate(`
    (() => {
      const bodyText = document.body?.innerText || '';
      const requiresAuth = /请先登录|登录后/.test(bodyText);
      const blocked = /验证码|安全验证|异常访问/.test(bodyText);
      const nick = document.querySelector('.user-name, .user-nick, .nick, [class*="nickname"]')?.innerText?.trim() || '';
      const html = document.body?.innerHTML || '';
      const userIdMatch = html.match(/['"]?userId['"]?\\s*[:=]\\s*['"]?(\\d+)/i);
      return { requiresAuth, blocked, domNick: nick, domUserId: userIdMatch?.[1] || '' };
    })()
  `);
  if (probe.blocked) {
    throw new AuthRequiredError('goofish.com', 'Xianyu blocked by verification / risk control');
  }
  if (probe.requiresAuth) {
    throw new AuthRequiredError('goofish.com', 'Xianyu /personal shows login prompt — anonymous');
  }
  const userId = probe.domUserId || unb;
  let decodedTracknick = '';
  if (tracknick) {
    try {
      decodedTracknick = JSON.parse('"' + tracknick.replace(/\\/g, '\\\\') + '"');
    } catch {
      decodedTracknick = tracknick;
    }
  }
  const nickname = probe.domNick || decodedTracknick;
  if (!userId && !nickname) {
    throw new CommandExecutionError('Xianyu /personal rendered but no user identity extractable — stale unb or layout drift');
  }
  return { user_id: String(userId), nickname: String(nickname) };
}

registerSiteAuthCommands({

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open https://www.goofish.com/login in the automated browser and log in manually or restore saved cookies
  2. Re-run verifyXianyuIdentity after the session is established
  3. Ensure persistent user-data-dir is used so cookies survive restarts
  4. Check that unb and tracknick cookies are present before verification

Example fix

// before
const id = await verifyXianyuIdentity(page); // throws if anonymous
// after
if (await hasXianyuIdentityCookie(page)) {
  const id = await verifyXianyuIdentity(page);
} else {
  await loginManuallyOrRestoreCookies(page);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.context().cookies('https://www.goofish.com');
const authed = cookies.some(c => c.name === 'unb') && cookies.some(c => c.name === 'tracknick');
if (!authed) await loginXianyu(page);

Type guard

function isAuthRequiredError(e) {
  return e instanceof AuthRequiredError || e?.name === 'AuthRequiredError';
}

Try / catch

try {
  const identity = await verifyXianyuIdentity(page);
} catch (e) {
  if (isAuthRequiredError(e)) {
    await openLoginAndAwaitSession(page, 'https://www.goofish.com/login');
    return verifyXianyuIdentity(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling verifyXianyuIdentity (or any xianyu auth-verify flow) when the browser page has no valid login session; probe.requiresAuth is true because /personal redirected to or displayed a login prompt.

Common situations: Cookies expired or were cleared; user logged out of goofish.com; automation runs in a fresh browser profile that never logged in; goofish risk control invalidated the session.

Related errors


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