jackwener/OpenCLI · error · AuthRequiredError

Chaoxing session cookies missing

Error message

Chaoxing session cookies missing

What it means

verifyChaoxingIdentity first checks the browser page's cookies for a non-empty UID, _uid, chaoxinguser, or cx_p_token cookie on i.chaoxing.com. If none exists it throws AuthRequiredError('chaoxing.com','Chaoxing session cookies missing') — the page is not logged into Chaoxing, so identity verification cannot proceed.

Source

Thrown at clis/chaoxing/auth.js:11

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasChaoxingSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });
  return cookies.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value);
}

async function verifyChaoxingIdentity(page) {
  if (!await hasChaoxingSessionCookie(page)) {
    throw new AuthRequiredError('chaoxing.com', 'Chaoxing session cookies missing');
  }
  await page.goto('https://i.chaoxing.com/');
  await page.wait(3);
  const probe = await page.evaluate(`
    (() => {
      if (/passport2\\.chaoxing\\.com\\/login/.test(location.href)) {
        return { kind: 'auth', detail: 'Chaoxing i.chaoxing.com redirected to passport2 login' };
      }
      const userIdCookie = (document.cookie.split('; ').find(c => /^(_uid|UID)=/.test(c)) || '').split('=')[1] || '';
      let userName = '';
      const unameCookie = (document.cookie.split('; ').find(c => /^uname=/.test(c)) || '').split('=')[1] || '';
      if (unameCookie) {
        try { userName = decodeURIComponent(unameCookie); } catch { userName = unameCookie; }
      }
      if (!userName) {
        const el = document.querySelector('.userTitle, .myInfo, .user-name, [class*=userName]');
        userName = (el?.innerText || '').trim();
      }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the chaoxing login command to establish a session, then retry
  2. Persist and reload cookies between runs (storageState) so the session survives restarts
  3. Verify with page.getCookies that at least one of UID/_uid/chaoxinguser/cx_p_token is present and non-empty
  4. Check that the login flow actually completed (no captcha/SSO redirect left pending)

Example fix

// before
await verifyChaoxingIdentity(page);
// after
const cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });
if (!cookies.some(c => /^(UID|_uid|cx_p_token)$/i.test(c.name))) {
  await chaoxingLogin(page); // establish session first
}
await verifyChaoxingIdentity(page);
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });
const loggedIn = cookies.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value);
if (!loggedIn) await chaoxingLogin(page);

Type guard

function hasSessionCookie(cs) { return cs.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value); }

Try / catch

try { const identity = await whoami(page); }
catch (e) { if (e instanceof AuthRequiredError && e.message.includes('cookies missing')) { await login(page); return whoami(page); } throw e; }

Prevention

When it happens

Trigger: Calling the chaoxing auth/whoami command with a fresh or logged-out Playwright page; cookies cleared by browser context reset; login previously failed silently so no identity cookie was ever set.

Common situations: Running commands before ever logging in; browser context recreated without restoring saved cookies; Chaoxing logged the account out server-side and cleared cookies.

Related errors


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