{"record":{"id":"49be35b691355863","repo":"jackwener/OpenCLI","slug":"amazon-com","errorCode":null,"errorMessage":"amazon.com","messagePattern":"amazon\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/amazon/auth.js","lineNumber":12,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasAmazonSessionCookies(page) {\n  const cookies = await page.getCookies({ url: 'https://www.amazon.com' });\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('at-main') || names.has('x-main');\n}\n\nasync function verifyAmazonIdentity(page) {\n  if (!await hasAmazonSessionCookies(page)) {\n    throw new AuthRequiredError('amazon.com', 'Amazon auth cookies (at-main / x-main) are missing');\n  }\n  await page.goto('https://www.amazon.com/', { waitUntil: 'load' });\n  await page.wait(3);\n  const probe = await page.evaluate(`\n    (() => {\n      const navLink = document.querySelector('#nav-link-accountList');\n      if (!navLink) {\n        return { kind: 'auth', detail: 'Amazon header missing nav-link-accountList — layout changed or robot challenge' };\n      }\n      const greeting = (navLink.querySelector('.nav-line-1, #nav-link-accountList-nav-line-1') || {}).textContent || '';\n      const trimmed = greeting.trim();\n      if (/sign\\\\s*in/i.test(trimmed)) {\n        return { kind: 'auth', detail: 'Amazon header shows \"Hello, sign in\" — anonymous' };\n      }\n      const m = trimmed.match(/^Hello,?\\\\s+(.+)$/i);\n      const name = m ? m[1].trim() : '';\n      if (!name) {\n        return { kind: 'auth', detail: 'Amazon greeting unparseable: ' + trimmed };","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/amazon/auth.js#L1-L30","documentation":"AuthRequiredError thrown by verifyAmazonIdentity before probing amazon.com: the shared Chrome profile holds no Amazon session cookies. The library requires either 'at-main' or 'x-main' (Amazon's main login tokens) for the https://www.amazon.com URL before it will scrape any authenticated surface. It is the library's way of saying 'log in first' rather than an unexpected failure.","triggerScenarios":"Any registered amazon auth command path that calls verifyAmazonIdentity (verify or poll) when page.getCookies({url:'https://www.amazon.com'}) returns no cookie named 'at-main' or 'x-main' — i.e. the user never signed in, the profile cookies were cleared, or the session belongs to a different amazon domain (e.g. amazon.co.uk sets at-main for that TLD only).","commonSituations":"Fresh Chrome profile with no Amazon login; user cleared cookies or used clearing-on-exit settings; logged into a different Amazon marketplace TLD; cookies expired after Amazon revoked the session; running against an automated profile that never completed interactive sign-in.","solutions":["Run the library's amazon login command and complete sign-in in the shared Chrome profile until at-main/x-main cookies exist","Verify cookies manually for https://www.amazon.com in the profile (DevTools > Application > Cookies) and confirm at-main or x-main is present","If signed into a non-.com marketplace, sign in to www.amazon.com specifically","If cookies keep disappearing, disable 'clear cookies on exit' / cookie-blocking extensions for amazon.com"],"exampleFix":"// before: calling verify with an anonymous profile\nconst who = await opencli.call('amazon auth whoami');\n// throws AuthRequiredError('amazon.com', 'Amazon auth cookies (at-main / x-main) are missing')\n\n// after: ensure login first, then verify\nif (!(await opencli.call('amazon auth status')).logged_in) {\n  await opencli.call('amazon auth login'); // complete sign-in interactively\n}\nconst who = await opencli.call('amazon auth whoami');","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://www.amazon.com' });\nif (!cookies.some(c => c.name === 'at-main' || c.name === 'x-main')) {\n  await opencli.call('amazon auth login'); // establish session first\n}","typeGuard":"function hasAmazonSession(cookies) {\n  return Array.isArray(cookies) && cookies.some(c => c.name === 'at-main' || c.name === 'x-main');\n}","tryCatchPattern":"try {\n  const who = await opencli.call('amazon auth verify');\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    await opencli.call('amazon auth login');\n    return retry();\n  }\n  throw e;\n}","preventionTips":["Check amazon auth status before every authenticated call","Keep the shared Chrome profile signed in and avoid cookie-clearing settings","Sign in to www.amazon.com specifically, not other marketplace TLDs"],"tags":["authentication","cookies","amazon","browser-automation"],"backgroundTag":"missing-auth-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}