jackwener/OpenCLI · error · AuthRequiredError

jianyu360.cn

Error message

jianyu360.cn

What it means

verifyJianyuIdentity throws AuthRequiredError('jianyu360.cn', 'Jianyu userid_secure cookie missing — anonymous') when the browser has no non-empty 'userid_secure' cookie for jianyu360.cn, meaning the session is anonymous. The check runs before probing the user's identity endpoint.

Source

Thrown at clis/jianyu/auth.js:11

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

async function hasJianyuUserCookie(page) {
  const cookies = await page.getCookies({ url: 'https://www.jianyu360.cn' });
  return cookies.some(c => c.name === 'userid_secure' && c.value);
}

async function verifyJianyuIdentity(page) {
  if (!await hasJianyuUserCookie(page)) {
    throw new AuthRequiredError('jianyu360.cn', 'Jianyu userid_secure cookie missing — anonymous');
  }
  await page.goto('https://www.jianyu360.cn/');
  await page.wait(2);
  const probe = await page.evaluate(`(async () => {
    try {
      const r = await fetch('/swordfish/frontPage/customer/sess/index', { credentials: 'include' });
      const text = await r.text();
      if (/<title>\\s*登录\\s*[-—]\\s*剑鱼标讯/.test(text)) {
        return { kind: 'auth', detail: 'Jianyu protected page returned login page — anonymous' };
      }
      const userIdMeta = text.match(/<meta[^>]+name=[\"'](?:user-id|userId)[\"'][^>]+content=[\"']([^\"']+)[\"']/)?.[1] || '';
      const userScript = text.match(/window\\.__USER__\\s*=\\s*(\\{[^}]+\\})/)?.[1] || '';
      let userId = userIdMeta;
      let name = '';
      if (userScript) {
        try {
          const u = JSON.parse(userScript);
          userId = userId || String(u.id || u.userId || '');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to https://www.jianyu360.cn in the connected Chrome profile
  2. Run the jianyu auth login flow and complete it in the browser
  3. Confirm the CLI is attached to the profile holding the Jianyu cookies
  4. Re-run the verify command after login

Example fix

// before
const me = await jianyuWhoami();
// after
try {
  const me = await jianyuWhoami();
} catch (e) {
  if (e.code === 'AUTH_REQUIRED') {
    await jianyuAuthLogin();
    const me = await jianyuWhoami();
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.jianyu360.cn' });
const authed = cookies.some(c => c.name === 'userid_secure' && c.value);
if (!authed) await jianyuAuthLogin();

Type guard

function hasJianyuSession(cookies) {
  return cookies.some(c => c.name === 'userid_secure' && c.value);
}

Try / catch

try {
  const me = await jianyuVerify();
} catch (e) {
  if (e.code === 'AUTH_REQUIRED') {
    await jianyuAuthLogin();
    return jianyuVerify();
  }
  throw e;
}

Prevention

When it happens

Trigger: Any jianyu auth verify / whoami / login poll where page.getCookies({ url: 'https://www.jianyu360.cn' }) contains no 'userid_secure' cookie or its value is empty.

Common situations: Never logged in to Jianyu360 in the automation profile; session expired and the cookie was cleared; user logged out; wrong browser profile attached.

Related errors


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