jackwener/OpenCLI · error · AuthRequiredError
jd.com
Error message
jd.com
What it means
verifyJdIdentity throws AuthRequiredError('jd.com') when the browser's cookie jar for JD contains neither the 'pin' nor 'thor' cookie, meaning no logged-in JD session exists. This is the library's pre-flight identity check before probing account details on home.jd.com.
Source
Thrown at clis/jd/auth.js:12
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasJdSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.jd.com' });
const names = new Set(cookies.map(c => c.name));
return names.has('pin') || names.has('thor');
}
async function verifyJdIdentity(page) {
if (!await hasJdSessionCookie(page)) {
throw new AuthRequiredError('jd.com', 'JD pin / thor cookie missing');
}
await page.goto('https://home.jd.com/');
await page.wait(3);
const probe = await page.evaluate(`
(() => {
const pinCookie = (document.cookie.split('; ').find(c => c.startsWith('pin=')) || '').split('=')[1] || '';
const decoded = pinCookie ? decodeURIComponent(pinCookie) : '';
if (!decoded) {
return { kind: 'auth', detail: 'JD pin cookie empty after decode' };
}
const nickEl = document.querySelector('.user-info, #aliveUserName, .name, .user-name');
const nickname = (nickEl && nickEl.textContent && nickEl.textContent.trim()) || '';
return { ok: true, pin: decoded, nickname };
})()
`);
if (probe?.kind === 'auth') throw new AuthRequiredError('jd.com', probe.detail);
if (!probe?.ok) throw new CommandExecutionError(`Unexpected JD probe: ${JSON.stringify(probe)}`);
return { pin: probe.pin, nickname: probe.nickname };View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to https://www.jd.com in the Chrome profile the CLI is connected to
- Run `jd auth login` and complete the browser login flow
- Verify the CLI is attached to the intended browser profile (one with JD cookies)
- After login, re-run the verify/whoami command
Example fix
// before
const me = await jdWhoami();
// after
if (!(await jdHasSessionCookie())) {
await jdAuthLogin();
}
const me = await jdWhoami(); Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.jd.com' });
const names = new Set(cookies.map(c => c.name));
if (!names.has('pin') && !names.has('thor')) {
await jdAuthLogin(); // pre-flight login before verify
} Type guard
function hasJdSession(cookies) {
const names = new Set(cookies.map(c => c.name));
return names.has('pin') || names.has('thor');
} Try / catch
try {
const me = await jdVerify();
} catch (e) {
if (e.code === 'AUTH_REQUIRED') return loginAndRetry();
throw e;
} Prevention
- Check for pin/thor cookies before JD calls
- Always complete the jd auth login flow before scripted JD usage
- Confirm the correct Chrome profile is connected
- Treat AUTH_REQUIRED (exit NOPERM) as 'log in', not a bug
When it happens
Trigger: Any jd auth verify / whoami / login poll invocation where page.getCookies() for JD returns no 'pin' and no 'thor' cookie — anonymous profile, logged-out browser, or cookies cleared.
Common situations: Fresh automation profile never logged in to JD; user logged out manually; JD expired/cleared the session cookie; wrong Chrome profile connected (cookies live in another profile).
Related errors
- 1point3acres Discuz *_auth cookie missing
- dianping.com
- Douban dbcl2 / ck cookies missing
- hupu.com
- jd add-cart requires a logged-in JD session
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cde886542947f0bb.
Report an issue: GitHub.