jackwener/OpenCLI · error · AuthRequiredError
zsxq.com
Error message
zsxq.com
What it means
ensureZsxqAuth checks the browser session for zsxq login state; on any failure — including exceptions thrown inside the check — it throws AuthRequiredError('zsxq.com'). This is the library's gate telling you that no valid zsxq session exists and the requested operation cannot proceed until you authenticate.
Source
Thrown at clis/zsxq/utils.js:46
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.zsxq.com/v2/groups', true);
xhr.withCredentials = true;
xhr.setRequestHeader('accept', 'application/json');
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
try { resolve(JSON.parse(xhr.responseText)); }
catch { resolve(null); }
} else { resolve(null); }
};
xhr.onerror = () => resolve(null);
xhr.send();
});
return r !== null;
} catch { return false; }
})()
`);
if (!result) {
throw new AuthRequiredError('zsxq.com');
}
}
catch (err) {
if (err instanceof AuthRequiredError)
throw err;
throw new AuthRequiredError('zsxq.com');
}
}
export async function getCookieValue(page, name) {
const cookies = await page.getCookies({ domain: SITE_DOMAIN });
return cookies.find(cookie => cookie.name === name)?.value;
}
export async function getActiveGroupId(page) {
const groupId = await page.evaluate(`
(() => {
const target = localStorage.getItem('target_group');
if (target) {
try {View on GitHub (pinned to 49907e53dc)
Solutions
- Run the zsxq login command and complete authentication in the browser, then retry the original command.
- Use a persistent browser profile so cookies survive between runs.
- Verify manually in the same profile that zsxq.com shows you as logged in.
- Catch AuthRequiredError in your automation and trigger the login flow automatically before retrying.
Example fix
// before
await listTopics(page); // throws AuthRequiredError
// after
try {
await listTopics(page);
} catch (e) {
if (e instanceof AuthRequiredError) {
await loginZsxq(page); // interactive flow
return listTopics(page);
}
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
// preflight auth check before any zsxq command
const r = await page.request.get('https://api.zsxq.com/v2/users/self');
if (!r.ok()) await loginZsxq(page); Type guard
const isAuthRequired = (e) => e instanceof AuthRequiredError || e?.name === 'AuthRequiredError';
Try / catch
try {
return await runZsxqCommand(args);
} catch (e) {
if (isAuthRequired(e)) {
await loginZsxq(page);
return runZsxqCommand(args);
}
throw e;
} Prevention
- Always establish a session (login flow) before invoking zsxq commands.
- Use persistent browser storage so cookies persist across runs.
- Gate automation runs on a cheap login-state probe instead of failing mid-job.
When it happens
Trigger: Calling any zsxq command before login: the session probe (cookie/API check) returns false, or the check itself throws (navigation error, closed page), both of which funnel into AuthRequiredError.
Common situations: Fresh browser profile with no cookies; session expired since last run; automated run on a machine where the interactive login never happened; browser page crashed during the probe.
Related errors
- ChatGPT project requires a logged-in ChatGPT session.
- Claude requires a logged-in browser session.
- Xianyu item detail requires a logged-in browser session
- Note comments require login
- 1point3acres Discuz *_auth cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ddb1715cf5e9b800.
Report an issue: GitHub.