jackwener/OpenCLI · error · CliError
AUTH_REQUIRED
AUTH_REQUIRED
Error message
Not logged in to WeRead
What it means
postWebApiWithCookies posts to the WeRead web API using cookies extracted from a local Chrome login. When the server responds with HTTP 401, it throws this CliError with code AUTH_REQUIRED, meaning the request was not authenticated — the extracted cookies are missing, expired, or no longer accepted by WeRead.
Source
Thrown at clis/weread/ai-outline.js:35
const merged = new Map();
for (const c of domainCookies) merged.set(c.name, c);
for (const c of apiCookies) merged.set(c.name, c);
const cookieHeader = buildCookieHeader(Array.from(merged.values()));
const resp = await fetch(url, {
method: 'POST',
headers: {
'User-Agent': WEREAD_UA,
'Content-Type': 'application/json',
'Origin': WEREAD_WEB_ORIGIN,
'Referer': `${WEREAD_WEB_ORIGIN}/`,
...(cookieHeader ? { 'Cookie': cookieHeader } : {}),
},
body: JSON.stringify(body),
});
if (resp.status === 401) {
throw new CliError('AUTH_REQUIRED', 'Not logged in to WeRead', 'Please log in to weread.qq.com in Chrome first');
}
let data;
try {
data = await resp.json();
} catch {
throw new CliError('PARSE_ERROR', `Invalid JSON response for ${path}`, 'WeRead may have returned an HTML error page');
}
if (data?.errcode === -2010 || data?.errcode === -2012) {
throw new CliError('AUTH_REQUIRED', 'Not logged in to WeRead', 'Please log in to weread.qq.com in Chrome first');
}
if (!resp.ok) {
throw new CliError('FETCH_ERROR', `HTTP ${resp.status} for ${path}`, 'WeRead API may be temporarily unavailable');
}
return data;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Open weread.qq.com in Chrome and log in (again), then re-run the command so fresh cookies are extracted.
- Confirm the CLI is reading the same Chrome profile you logged in with (profile selection / env override).
- Clear WeRead cookies and log in cleanly if the session is in a half-valid state.
- Check whether a Chrome update changed the cookie store format and update/re-authenticate accordingly.
Example fix
// before (headless CI, no Chrome login)
await chapterData(bookId);
// after: pre-authenticate, then retry
exec('google-chrome --profile-directory=Default https://weread.qq.com'); // log in once
await chapterData(bookId); Defensive patterns
Strategy: try-catch
Validate before calling
// best-effort pre-check that cookies exist before calling
const cookies = await extractChromeCookies('weread.qq.com');
if (!cookies || !cookies.includes('vid=')) {
throw new Error('No WeRead session cookies found — log in to weread.qq.com in Chrome first');
} Type guard
function hasWeReadCookies(cookieHeader) { return typeof cookieHeader === 'string' && /(?:^|;\s*)vid=/.test(cookieHeader); } Try / catch
try {
const data = await chapterData(bookId);
} catch (e) {
if (e instanceof CliError && e.code === 'AUTH_REQUIRED') {
console.error('Not logged in. Open weread.qq.com in Chrome and log in, then retry.');
process.exitCode = 3;
} else throw e;
} Prevention
- Log in to weread.qq.com in Chrome on the same machine/profile before running batch jobs.
- Check for an AUTH_REQUIRED code before retrying — retrying auth errors never helps.
- Refresh cookies proactively before long-running scripts.
- In CI, either persist a valid cookie jar or skip WeRead-dependent steps.
When it happens
Trigger: chapterData calling postWebApiWithCookies after the user has logged out of weread.qq.com in Chrome, cookies expired, or no Chrome cookie store exists so no Cookie header is sent.
Common situations: Users running the CLI on a machine/browser profile where they never logged into WeRead; sessions invalidated by WeRead after a password change; headless/CI environments with no Chrome profile; cookie extraction breaking after a Chrome version update.
Related errors
- 12306 tk auth cookie missing
- ${label} returned HTTP ${resp.status}: ${summarizeApiError(p
- amazon.com
- Bilibili ${label} API requires login or permission: ${messag
- Boss wt2 / t cookies missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c9f4137f863e9328.
Report an issue: GitHub.