jackwener/OpenCLI · error · AuthRequiredError

auth

Error message

auth

What it means

The in-page whoami probe returns {kind:'auth'} in three cases: the meta[current-user-username] tag is missing, /u/<self>.json returns HTTP 401/403, or the JSON payload lacks user.id. Each is converted to AuthRequiredError for linux.do — the session cookie exists but the server considers the user unauthenticated for API access.

Source

Thrown at clis/linux-do/auth.js:35

      const u = document.querySelector('meta[name="current-user-username"]')?.getAttribute('content') || '';
      if (!u) return { kind: 'auth', detail: 'Linux.do meta[current-user-username] missing — anonymous' };
      const r = await fetch('/u/' + encodeURIComponent(u) + '.json', {
        credentials: 'include',
        headers: { Accept: 'application/json' },
      });
      if (r.status === 401 || r.status === 403) {
        return { kind: 'auth', detail: 'Linux.do /u/<self>.json HTTP ' + r.status };
      }
      if (!r.ok) return { kind: 'http', httpStatus: r.status };
      const d = await r.json();
      const user = d?.user;
      if (!user || !user.id) return { kind: 'auth', detail: 'Linux.do /u/<self>.json missing user.id' };
      return { ok: true, user_id: String(user.id), username: String(user.username || u), name: String(user.name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (probe?.kind === 'auth') throw new AuthRequiredError('linux.do', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Linux.do /u/<self>.json`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`Linux.do whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Linux.do probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, username: probe.username, name: probe.name };
}

registerSiteAuthCommands({
  site: 'linux-do',
  domain: 'linux.do',
  loginUrl: 'https://linux.do/login',
  columns: ['user_id', 'username', 'name'],
  quickCheck: hasLinuxDoSessionCookie,
  verify: verifyLinuxDoIdentity,
  poll: async (page) => {
    if (!await hasLinuxDoSessionCookie(page)) {
      throw new AuthRequiredError('linux.do', 'Waiting for Linux.do _t cookie');
    }
    return verifyLinuxDoIdentity(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login at https://linux.do/login to refresh the session, then retry verification
  2. Wait and retry if linux.do is rate-limiting or under a Cloudflare challenge
  3. Increase the post-navigation delay/retry so the page's meta tags are present before probing
  4. Check the account status on linux.do for suspension or forced logout
Defensive patterns

Strategy: try-catch

Validate before calling

// Cookie may exist but be invalid server-side; treat verify failures as 're-login'
const cookies = await page.getCookies({ url: 'https://linux.do' });
if (!cookies.some(c => c.name === '_t' && c.value)) await linuxDoLogin();

Type guard

const probeSaysAuth = (probe) => probe && probe.kind === 'auth';

Try / catch

try {
  const identity = await verifyLinuxDoIdentity(page);
} catch (e) {
  if (e.name === 'AuthRequiredError') { await linuxDoLogin(); return verifyLinuxDoIdentity(page); }
  throw e;
}

Prevention

When it happens

Trigger: '_t' cookie present but invalid/expired server-side; linux.do returning 401/403 on the /u/<username>.json endpoint; page not fully loaded so meta tag absent after the 2s wait; suspended/limited account lacking user.id in the API response.

Common situations: Cookie expired while the client still holds it (quickCheck passes, verify fails); linux.do behind maintenance or Cloudflare challenge; rate-limited Discourse API; user suspended or logged out remotely.

Related errors


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