jackwener/OpenCLI · error · AuthRequiredError

WeRead wr_vid cookie missing

Error message

WeRead wr_vid cookie missing

What it means

verifyWereadIdentity in clis/weread/auth.js throws AuthRequiredError when the browser page's cookies for https://weread.qq.com contain no non-empty wr_vid cookie — WeRead's login session identifier. The library requires this cookie to prove the user is logged in before any WeRead command runs.

Source

Thrown at clis/weread/auth.js:11

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

async function hasWereadSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://weread.qq.com' });
  return cookies.some(c => c.name === 'wr_vid' && c.value);
}

async function verifyWereadIdentity(page) {
  if (!await hasWereadSessionCookie(page)) {
    throw new AuthRequiredError('weread.qq.com', 'WeRead wr_vid cookie missing');
  }
  await page.goto('https://weread.qq.com/');
  await page.wait(2);
  const result = await page.evaluate(`(async () => {
    try {
      const wrVid = (document.cookie.split('; ').find(c => c.startsWith('wr_vid=')) || '').split('=')[1] || '';
      if (!wrVid) {
        return { kind: 'auth', detail: 'WeRead wr_vid cookie absent in document.cookie' };
      }
      const res = await fetch('/web/user', { credentials: 'include', headers: { 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'WeRead /web/user HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (d && d.errCode && d.errCode !== 0) {
        return { kind: 'auth', detail: 'WeRead /web/user errCode=' + d.errCode };
      }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open https://weread.qq.com/ in the attached Chrome browser and log in with your WeChat/WeRead account.
  2. Re-run the command after confirming wr_vid exists (DevTools > Application > Cookies for weread.qq.com).
  3. Ensure the CLI is using the correct Chrome profile/directory that holds the login.
  4. If cookies are being cleared, disable auto-clear-on-exit for weread.qq.com or use a persistent (non-incognito) profile.

Example fix

// before: running commands with no login
$ opencli weread shelf
AuthRequiredError: WeRead wr_vid cookie missing
// after: log in first
$ opencli weread login   # opens https://weread.qq.com/, log in with WeChat
$ opencli weread shelf
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://weread.qq.com' });
if (!cookies.some(c => c.name === 'wr_vid' && c.value)) {
  console.error('Not logged in to WeRead — run the login command first.');
}

Try / catch

try { await wereadCommand(args); } catch (e) {
  if (e instanceof AuthRequiredError || /wr_vid cookie missing/.test(e.message)) {
    console.error('Run `opencli weread login` and log in at weread.qq.com in the attached browser.');
  } else throw e;
}

Prevention

When it happens

Trigger: hasWereadSessionCookie(page) returns false because no wr_vid cookie exists in the controlled Chrome profile — the user never logged in to weread.qq.com, the session expired and WeRead cleared the cookie, or the wrong browser profile is attached.

Common situations: Fresh machine/profile where the user never logged in; WeRead logged the session out; cookie cleared by browser cleanup or incognito mode; pointing the CLI at a different Chrome profile than the one with the WeRead login.

Related errors


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