jackwener/OpenCLI · error · AuthRequiredError
reddit.com
reddit.com
Error message
Reddit reddit_session cookie missing
What it means
This AuthRequiredError is thrown by verifyRedditIdentity in clis/reddit/auth.js when the browser context has no non-empty `reddit_session` cookie for reddit.com. The library requires that cookie as a precondition before probing /api/me.json, because Reddit's personalized/identity APIs only work for an authenticated session. It signals the user must log in to Reddit in the automation browser.
Source
Thrown at clis/reddit/auth.js:11
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasRedditSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.reddit.com' });
return cookies.some(c => c.name === 'reddit_session' && c.value);
}
async function verifyRedditIdentity(page) {
if (!await hasRedditSessionCookie(page)) {
throw new AuthRequiredError('reddit.com', 'Reddit reddit_session cookie missing');
}
await page.goto('https://www.reddit.com/');
await page.wait(2);
const result = await page.evaluate(`(async () => {
try {
const res = await fetch('/api/me.json', { credentials: 'include', headers: { 'Accept': 'application/json' } });
if (res.status === 401 || res.status === 403) {
return { kind: 'auth', detail: 'Reddit /api/me.json HTTP ' + res.status };
}
if (!res.ok) return { kind: 'http', httpStatus: res.status };
const d = await res.json();
const data = d && d.data;
if (!data || !data.name) {
return { kind: 'auth', detail: 'Reddit /api/me.json 200 but no data.name — anonymous' };
}
return { ok: true, username: String(data.name), id: String(data.id || '') };
} catch (e) {
return { kind: 'exception', detail: String(e && e.message || e) };View on GitHub (pinned to 49907e53dc)
Solutions
- Run the library's login flow for the reddit site (opens https://www.reddit.com/login) and complete an interactive login so the reddit_session cookie is set.
- Verify the browser profile/persisted context directory is the one the CLI actually reuses, so cookies survive restarts.
- Manually log in to reddit.com in the automation browser and re-run the command.
- Check that no extension/proxy is stripping cookies from https://www.reddit.com.
Example fix
// before (no session) opencli reddit home --limit 10 // after (login first) opencli reddit login # completes browser login, sets reddit_session opencli reddit home --limit 10
Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.reddit.com' });
if (!cookies.some(c => c.name === 'reddit_session' && c.value)) {
await runRedditLogin(page); // establish session before calling commands
} Type guard
function hasRedditSession(cookies) {
return Array.isArray(cookies) && cookies.some(c => c?.name === 'reddit_session' && typeof c.value === 'string' && c.value.length > 0);
} Try / catch
try {
await opencli.reddit.home({ limit: 10 });
} catch (e) {
if (e instanceof AuthRequiredError && e.code === 'reddit.com') {
await opencli.reddit.login();
return opencli.reddit.home({ limit: 10 });
}
throw e;
} Prevention
- Always run the site login flow before auth-required commands in fresh environments.
- Persist the browser profile directory so cookies survive restarts and CI runs.
- Proactively check for the reddit_session cookie before invoking commands.
- Never wipe or reset the automation profile without re-logging in afterwards.
When it happens
Trigger: Calling any registered reddit site-auth command (or `home`, which routes through verifyRedditIdentity) before ever completing a browser login: page.getCookies({url:'https://www.reddit.com'}) returns no `reddit_session` cookie, or one with an empty value.
Common situations: Fresh browser profile / first run of the CLI; the user skipped the interactive login step; cookies were cleared or the profile directory was wiped; a corporate proxy or cookie-blocking extension strips Reddit cookies.
Related errors
- LinkedIn li_at cookie missing
- Pixiv PHPSESSID cookie missing
- Toutiao sessionid cookie missing
- V2EX A2 session cookie missing — anonymous
- Band band_session cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/220ec48a618de071.
Report an issue: GitHub.