{"record":{"id":"e84c932c1beeb03d","repo":"jackwener/OpenCLI","slug":"jd-cart-requires-a-logged-in-jd-session","errorCode":null,"errorMessage":"jd cart requires a logged-in JD session","messagePattern":"jd cart requires a logged-in JD session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/jd/cart.js","lineNumber":76,"sourceCode":"          const priceMatch = line.match(/¥([\\\\d,.]+)/);\n          if (priceMatch && i > 0) {\n            const title = lines[i - 1];\n            if (title && title.length > 5 && title.length < 200 && !title.startsWith('¥')) {\n              items.push({\n                index: items.length + 1,\n                title: title.slice(0, 80),\n                price: '¥' + priceMatch[1],\n                quantity: '',\n                sku: '',\n              });\n            }\n          }\n        }\n        return { items };\n      })()\n    `);\n        if (data?.error === 'auth-required') {\n            throw new AuthRequiredError('jd cart requires a logged-in JD session');\n        }\n        return Array.isArray(data?.items) ? data.items : [];\n    },\n});\n","sourceCodeStart":58,"sourceCodeEnd":81,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jd/cart.js#L58-L81","documentation":"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.","triggerScenarios":"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'.","commonSituations":"Expired JD session (common after a day or two); browser logged out; wrong profile connected; JD anti-bot interstitial resembling a login redirect.","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"],"exampleFix":"// before\nconst items = await jdCart();\n// after\ntry {\n  const items = await jdCart();\n} catch (e) {\n  if (e.code === 'AUTH_REQUIRED') {\n    await jdAuthLogin();\n    const items = await jdCart();\n  }\n}","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://www.jd.com' });\nif (!cookies.some(c => (c.name === 'pin' || c.name === 'thor') && c.value)) {\n  await jdAuthLogin();\n}","typeGuard":"function isAuthRequiredError(e) { return e?.code === 'AUTH_REQUIRED'; }","tryCatchPattern":"try {\n  const items = await jdCart();\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await jdAuthLogin();\n    return jdCart();\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["auth","jd","cart","login-required"],"backgroundTag":"site-session-not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}