jackwener/OpenCLI · error · AuthRequiredError

rednote.com

Error message

rednote.com

What it means

This AuthRequiredError is thrown by verifyRednoteIdentity when hasRednoteSessionCookie finds no non-empty 'web_session' cookie for https://www.rednote.com in the browser context. The library uses this error to signal that the user is not logged in to rednote.com and must authenticate before site-specific commands can run. The first argument ('rednote.com') identifies the site requiring auth and the detail explains the missing cookie.

Source

Thrown at clis/rednote/auth.js:11

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

async function hasRednoteSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://www.rednote.com' });
  return cookies.some(c => c.name === 'web_session' && c.value);
}

async function verifyRednoteIdentity(page) {
  if (!await hasRednoteSessionCookie(page)) {
    throw new AuthRequiredError('rednote.com', 'Rednote web_session cookie missing');
  }
  await page.goto('https://www.rednote.com/explore');
  await page.wait(2);
  const probe = await page.evaluate(`
    (() => {
      const state = window.__INITIAL_STATE__;
      if (!state?.user) {
        return { kind: 'auth', detail: 'Rednote __INITIAL_STATE__.user missing' };
      }
      const loggedIn = state.user.loggedIn?._value;
      const userInfo = state.user.userInfo?._value || {};
      if (loggedIn !== true) {
        return { kind: 'auth', detail: 'Rednote loggedIn._value=' + String(loggedIn) + ' — anonymous' };
      }
      const userId = String(userInfo.userId || userInfo.user_id || '');
      const nickname = String(userInfo.nickname || userInfo.name || '');
      if (!userId) {
        return { kind: 'auth', detail: 'Rednote logged-in but userId missing — stale session' };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the rednote login/registration flow (registerSiteAuthCommands provides it) to obtain a web_session cookie, then retry.
  2. Open rednote.com in the automation browser and log in manually if using a persistent profile.
  3. Check that cookies aren't being wiped between runs — use a persistent user data dir instead of a fresh incognito context.
  4. Verify the cookie's domain: log in on www.rednote.com (not a regional mirror) so the cookie matches the 'https://www.rednote.com' URL scope used by getCookies.
  5. Catch AuthRequiredError in caller code and trigger the login flow automatically before retrying the command.

Example fix

// before: calling site commands directly and crashing
await rednoteCommand(page);

// after: pre-check and authenticate when needed
import { AuthRequiredError } from './errors.js';
try {
  await rednoteCommand(page);
} catch (e) {
  if (e instanceof AuthRequiredError && e.site === 'rednote.com') {
    await rednoteLogin(page);
    await rednoteCommand(page);
  } else throw e;
}
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.rednote.com' });
const hasSession = cookies.some(c => c.name === 'web_session' && c.value);
if (!hasSession) {
  await rednoteLogin(page); // authenticate before running site commands
}

Type guard

function hasRednoteSession(cookies) {
  return Array.isArray(cookies) &&
    cookies.some(c => c.name === 'web_session' && typeof c.value === 'string' && c.value.length > 0);
}

Try / catch

try {
  await rednoteCommand(page);
} catch (e) {
  if (e instanceof AuthRequiredError && e.message.includes('rednote.com')) {
    await rednoteLogin(page);
    return rednoteCommand(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any rednote command that ends in verifyRednoteIdentity when the page's cookie jar for rednote.com lacks a web_session cookie, or has one with an empty value — i.e., never logged in, logged out, or cookies cleared/misscoped.

Common situations: Fresh browser profile with no prior rednote login; user logged out or session expired and Reddit-style cookie cleanup removed web_session; cookies cleared by privacy tooling or incognito mode; getCookies({ url }) scope mismatch so the cookie exists under a different domain/path than 'https://www.rednote.com'.

Related errors


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