jackwener/OpenCLI · error · AuthRequiredError

www.xiaohongshu.com

Error message

www.xiaohongshu.com

What it means

AuthRequiredError (exit code 77, EX_NOPERM) is thrown when the final URL after navigation is a /login path — the site bounced the unauthenticated session to its login page. The domain www.xiaohongshu.com is the login target; the fix is to log in to that domain in the connected browser.

Source

Thrown at clis/xiaohongshu/follow.js:189

        }
        try {
            const userId = assertUserId(kwargs['user-id']);
            const url = `https://www.xiaohongshu.com/user/profile/${userId}`;
            await page.goto(url);
            await page.wait({ time: PROFILE_SETTLE_MS / 1000 });

            const hrefRaw = unwrapEvaluateResult(await page.evaluate('() => location.href'));
            if (typeof hrefRaw !== 'string') {
                throw new CommandExecutionError('xiaohongshu/follow: malformed current-url payload');
            }
            const parsedHref = new URL(hrefRaw);
            if (parsedHref.protocol !== 'https:' || !isXiaohongshuHost(parsedHref.hostname)) {
                throw new CommandExecutionError(
                    `xiaohongshu/follow: expected Xiaohongshu profile host, got ${parsedHref.hostname}`,
                );
            }
            if (/\/login(?:[/?#]|$)/i.test(parsedHref.pathname)) {
                throw new AuthRequiredError('www.xiaohongshu.com');
            }
            const currentProfile = parsedHref.pathname.match(/^\/user\/profile\/([a-zA-Z0-9]{8,32})\/?$/);
            if (currentProfile?.[1] !== userId) {
                throw new CommandExecutionError(
                    `xiaohongshu/follow: expected profile ${userId}, got ${parsedHref.pathname}`,
                );
            }

            const result = requireActionResult(
                await page.evaluate(buildFollowScript()),
                'follow-action',
            );
            if (!result.ok) {
                throw new CommandExecutionError(
                    `xiaohongshu/follow failed: ${result.reason ?? 'unknown reason'}`,
                );
            }
            return [{ status: result.state, user_id: userId, url }];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open Chrome/Chromium, go to https://www.xiaohongshu.com, and log in manually, then re-run the command.
  2. Verify login by running a read-only xiaohongshu command (e.g. feed) before write actions like follow.
  3. Ensure the CLI is using the browser profile where you are logged in (check the configured profile).

Example fix

// before
opencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a
// after
# log in to https://www.xiaohongshu.com in the connected browser first
opencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check login state before a write command
const onLogin = await page.evaluate('() => /\\/login(?:[/?#]|$)/i.test(location.pathname)');
if (onLogin) throw new Error('Log in to www.xiaohongshu.com first');

Type guard

const isAuthRequired = (e) => e instanceof Error && e.code === 'AUTH_REQUIRED';

Try / catch

try {
  await follow(page, userId);
} catch (err) {
  if (err.code === 'AUTH_REQUIRED') {
    console.error('Open Chrome and log in to https://www.xiaohongshu.com, then retry.');
    process.exitCode = 77;
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Running follow while the browser profile's xiaohongshu.com session cookie is missing or expired, so the profile URL redirects to /login during the settle wait.

Common situations: Cookie expiration after weeks of no manual login; logging out in the connected Chrome profile; using a fresh/clean browser profile with no session; site forcing re-login after suspicious activity.

Related errors


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