jackwener/OpenCLI · error · AuthRequiredError

jd cart requires a logged-in JD session

Error message

jd cart requires a logged-in JD session

What it means

The jd cart command throws AuthRequiredError when the in-page cart scraper returns { error: 'auth-required' }, meaning JD served a login wall instead of the cart page. Reading the cart requires a logged-in JD session and the command refuses to return partial/anonymous data.

Source

Thrown at clis/jd/cart.js:76

          const priceMatch = line.match(/¥([\\d,.]+)/);
          if (priceMatch && i > 0) {
            const title = lines[i - 1];
            if (title && title.length > 5 && title.length < 200 && !title.startsWith('¥')) {
              items.push({
                index: items.length + 1,
                title: title.slice(0, 80),
                price: '¥' + priceMatch[1],
                quantity: '',
                sku: '',
              });
            }
          }
        }
        return { items };
      })()
    `);
        if (data?.error === 'auth-required') {
            throw new AuthRequiredError('jd cart requires a logged-in JD session');
        }
        return Array.isArray(data?.items) ? data.items : [];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to https://www.jd.com in the connected Chrome profile
  2. Run `jd auth login` / verify first, then retry `jd cart`
  3. Clear stale JD cookies and log in fresh if the session is half-expired
  4. Confirm the CLI is attached to the profile that holds JD cookies

Example fix

// before
const items = await jdCart();
// after
try {
  const items = await jdCart();
} catch (e) {
  if (e.code === 'AUTH_REQUIRED') {
    await jdAuthLogin();
    const items = await jdCart();
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.jd.com' });
if (!cookies.some(c => (c.name === 'pin' || c.name === 'thor') && c.value)) {
  await jdAuthLogin();
}

Type guard

function isAuthRequiredError(e) { return e?.code === 'AUTH_REQUIRED'; }

Try / catch

try {
  const items = await jdCart();
} catch (e) {
  if (isAuthRequiredError(e)) {
    await jdAuthLogin();
    return jdCart();
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `jd cart` while the attached browser has no valid JD session; JD redirected the cart URL to a passport login page which the evaluate script detects and tags 'auth-required'.

Common situations: Expired JD session (common after a day or two); browser logged out; wrong profile connected; JD anti-bot interstitial resembling a login redirect.

Related errors


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