{"record":{"id":"c8a0bc183c1d7382","repo":"jackwener/OpenCLI","slug":"yuanbao-showed-wx-login-gate-anonymous-session","errorCode":null,"errorMessage":"Yuanbao showed wx login gate — anonymous session","messagePattern":"Yuanbao showed wx login gate — anonymous session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/yuanbao/auth.js","lineNumber":13,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\nimport { hasLoginGate, ensureYuanbaoPage, YUANBAO_DOMAIN, YUANBAO_URL } from './shared.js';\n\nasync function hasYuanbaoUserCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\n  return cookies.some(c => c.name === 'hy_user' && c.value);\n}\n\nasync function verifyYuanbaoIdentity(page) {\n  await ensureYuanbaoPage(page);\n  if (await hasLoginGate(page)) {\n    throw new AuthRequiredError(YUANBAO_DOMAIN, 'Yuanbao showed wx login gate — anonymous session');\n  }\n  const cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\n  const hyUser = cookies.find(c => c.name === 'hy_user')?.value || '';\n  if (!hyUser) {\n    throw new AuthRequiredError(YUANBAO_DOMAIN, 'Yuanbao hy_user cookie missing — anonymous session');\n  }\n  const probe = await page.evaluate(`\n    (() => {\n      const bodyText = document.body?.innerText || '';\n      const nickMatch = bodyText.match(/用户[a-z0-9]{4,}/i);\n      const state = window.__INITIAL_STATE__ || {};\n      const seen = new Set();\n      const stack = [state];\n      let stateNick = '';\n      while (stack.length) {\n        const node = stack.pop();\n        if (!node || typeof node !== 'object' || seen.has(node)) continue;\n        seen.add(node);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yuanbao/auth.js#L1-L31","documentation":"An AuthRequiredError thrown by verifyYuanbaoIdentity when the Yuanbao page currently shows the WeChat login gate, meaning the browser session is anonymous (not logged in). The library calls this verifier before any authenticated Yuanbao operation; a visible login gate proves there is no usable session, so it fails with an auth-required signal pointing at the Yuanbao domain.","triggerScenarios":"Running any yuanbao command that verifies identity (login quickCheck/verify, or flows calling verifyYuanbaoIdentity) when cookies are absent/expired and the site renders its wx login gate instead of the app.","commonSituations":"Expired hy_user session cookies; fresh environment never logged in; cookies cleared by browser cleanup; logging in on one machine profile and running the CLI against another.","solutions":["Run the yuanbao login flow to establish an authenticated session (scan the WeChat QR).","Re-import fresh Yuanbao cookies if you manage sessions manually.","Verify the persistent session profile wasn't cleared before running commands."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight check before any authenticated yuanbao call\nconst cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\nif (!cookies.some(c => c.name === 'hy_user' && c.value)) {\n  await run(['yuanbao', 'login']);\n}","typeGuard":"const hasYuanbaoUserCookie = (cookies) =>\n  Array.isArray(cookies) && cookies.some(c => c.name === 'hy_user' && !!c.value);","tryCatchPattern":"try {\n  await run(['yuanbao', 'detail', url]);\n} catch (e) {\n  if (e.name === 'AuthRequiredError' || /login gate/.test(e.message)) {\n    await run(['yuanbao', 'login']);\n    return run(['yuanbao', 'detail', url]);\n  }\n  throw e;\n}","preventionTips":["Run the login flow proactively when hy_user is missing or stale","Check cookie presence before batch runs","Don't share/clear the persistent browser profile between runs","Handle AuthRequiredError by routing to login, not retrying blind"],"tags":["yuanbao","authentication","login-gate"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}