jackwener/OpenCLI · error · AuthRequiredError

${probe.detail}

Error message

${probe.detail}

What it means

verifyV2exIdentity probes the V2EX top bar inside the browser page. If the probe returns kind:'auth' (e.g. no member link, or a member link with an empty username), the library throws AuthRequiredError for v2ex.com with the probe's detail message. It signals that the current browser session is not (or no longer) a logged-in V2EX session, so the identity cannot be verified and the user must authenticate. This is an expected, controlled error used by the site-auth polling flow.

Source

Thrown at clis/v2ex/auth.js:26

}

async function verifyV2exIdentity(page) {
  if (!await hasV2exAuthCookie(page)) {
    throw new AuthRequiredError('v2ex.com', 'V2EX A2 session cookie missing — anonymous');
  }
  await page.goto('https://www.v2ex.com/');
  await page.wait(1);
  const probe = await page.evaluate(`
    (() => {
      const link = document.querySelector('#Top a[href^="/member/"]');
      if (!link) return { kind: 'auth', detail: 'V2EX top bar has no member link — anonymous session' };
      const href = link.getAttribute('href') || '';
      const username = (link.innerText || href.replace('/member/', '')).trim();
      if (!username) return { kind: 'auth', detail: 'V2EX member link present but username empty' };
      return { ok: true, username };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('v2ex.com', probe.detail);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected V2EX probe: ${JSON.stringify(probe)}`);
  return { username: probe.username };
}

registerSiteAuthCommands({
  site: 'v2ex',
  domain: 'v2ex.com',
  loginUrl: 'https://www.v2ex.com/signin',
  columns: ['username'],
  quickCheck: hasV2exAuthCookie,
  verify: verifyV2exIdentity,
  poll: async (page) => {
    if (!await hasV2exAuthCookie(page)) {
      throw new AuthRequiredError('v2ex.com', 'Waiting for V2EX A2 session cookie');
    }
    return verifyV2exIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the v2ex login command to complete the browser sign-in flow at https://www.v2ex.com/signin until the A2 cookie and member link are present.
  2. Verify the A2 cookie exists and is non-empty (page.getCookies for https://www.v2ex.com); re-login if it is missing or expired.
  3. Manually visit v2ex.com in the automation browser to clear any Cloudflare challenge, then retry the verify command.
  4. If logged in but the error persists, check whether V2EX changed its top-bar markup and update the selector '#Top a[href^="/member/"]'.

Example fix

// before: polling verify while anonymous
await verifyV2exIdentity(page); // AuthRequiredError
// after: ensure login first
if (!await hasV2exAuthCookie(page)) {
  await openLoginPage('https://www.v2ex.com/signin'); // user completes login
}
const { username } = await verifyV2exIdentity(page);
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.v2ex.com' });
const loggedIn = cookies.some(c => c.name === 'A2' && c.value);
if (!loggedIn) throw new Error('Run v2ex login first: no A2 session cookie');

Type guard

function isAuthProbe(p) { return !!p && typeof p === 'object' && p.kind === 'auth' && typeof p.detail === 'string'; }
function isOkProbe(p) { return !!p && typeof p === 'object' && p.ok === true && typeof p.username === 'string' && p.username.length > 0; }

Try / catch

try {
  const { username } = await verifyV2exIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    // launch login flow at https://www.v2ex.com/signin and retry after login
  } else throw e;
}

Prevention

When it happens

Trigger: Calling verifyV2exIdentity (or the v2ex auth verify/poll command) when page.evaluate returns {kind:'auth', detail:...}: (1) no #Top a[href^="/member/"] element exists (anonymous session or V2EX layout change), or (2) the member link exists but its innerText and href-derived username are both empty.

Common situations: User never logged in via the loginUrl flow; the A2 session cookie expired so V2EX renders the logged-out top bar; Cloudflare or a bot-challenge page replaced the real homepage DOM; V2EX redesigns the #Top nav so the member-link selector no longer matches.

Related errors


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