jackwener/OpenCLI · error · AuthRequiredError

amazon.com

Error message

amazon.com

What it means

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.

Solutions

  1. Run the library's amazon login command and complete sign-in in the shared Chrome profile until at-main/x-main cookies exist
  2. Verify cookies manually for https://www.amazon.com in the profile (DevTools > Application > Cookies) and confirm at-main or x-main is present
  3. If signed into a non-.com marketplace, sign in to www.amazon.com specifically
  4. If cookies keep disappearing, disable 'clear cookies on exit' / cookie-blocking extensions for amazon.com

Example fix

// before: calling verify with an anonymous profile
const who = await opencli.call('amazon auth whoami');
// throws AuthRequiredError('amazon.com', 'Amazon auth cookies (at-main / x-main) are missing')

// after: ensure login first, then verify
if (!(await opencli.call('amazon auth status')).logged_in) {
  await opencli.call('amazon auth login'); // complete sign-in interactively
}
const who = await opencli.call('amazon auth whoami');
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.amazon.com' });
if (!cookies.some(c => c.name === 'at-main' || c.name === 'x-main')) {
  await opencli.call('amazon auth login'); // establish session first
}

Type guard

function hasAmazonSession(cookies) {
  return Array.isArray(cookies) && cookies.some(c => c.name === 'at-main' || c.name === 'x-main');
}

Try / catch

try {
  const who = await opencli.call('amazon auth verify');
} catch (e) {
  if (e.name === 'AuthRequiredError') {
    await opencli.call('amazon auth login');
    return retry();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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

Appendix: source

Thrown at clis/amazon/auth.js:12

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasAmazonSessionCookies(page) {
  const cookies = await page.getCookies({ url: 'https://www.amazon.com' });
  const names = new Set(cookies.map(c => c.name));
  return names.has('at-main') || names.has('x-main');
}

async function verifyAmazonIdentity(page) {
  if (!await hasAmazonSessionCookies(page)) {
    throw new AuthRequiredError('amazon.com', 'Amazon auth cookies (at-main / x-main) are missing');
  }
  await page.goto('https://www.amazon.com/', { waitUntil: 'load' });
  await page.wait(3);
  const probe = await page.evaluate(`
    (() => {
      const navLink = document.querySelector('#nav-link-accountList');
      if (!navLink) {
        return { kind: 'auth', detail: 'Amazon header missing nav-link-accountList — layout changed or robot challenge' };
      }
      const greeting = (navLink.querySelector('.nav-line-1, #nav-link-accountList-nav-line-1') || {}).textContent || '';
      const trimmed = greeting.trim();
      if (/sign\\s*in/i.test(trimmed)) {
        return { kind: 'auth', detail: 'Amazon header shows "Hello, sign in" — anonymous' };
      }
      const m = trimmed.match(/^Hello,?\\s+(.+)$/i);
      const name = m ? m[1].trim() : '';
      if (!name) {
        return { kind: 'auth', detail: 'Amazon greeting unparseable: ' + trimmed };

View on GitHub (pinned to 49907e53dc)