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
- Log in to https://www.jd.com in the connected Chrome profile
- Run `jd auth login` / verify first, then retry `jd cart`
- Clear stale JD cookies and log in fresh if the session is half-expired
- 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
- Verify JD session before read commands that need identity
- Refresh JD login daily in automation environments
- Detect login-wall redirects early and re-authenticate
- Keep one dedicated, logged-in profile for CLI automation
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
- jd add-cart requires a logged-in JD session
- jd.com
- 1point3acres Discuz *_auth cookie missing
- 需要登录一亩三分地后再使用该命令
- Cookie 已过期!请在当前 Chrome 浏览器中重新登录 BOSS 直聘。
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e84c932c1beeb03d.
Report an issue: GitHub.