{"record":{"id":"a662b963d7184e50","repo":"jackwener/OpenCLI","slug":"weread-wr-vid-cookie-missing","errorCode":null,"errorMessage":"WeRead wr_vid cookie missing","messagePattern":"WeRead wr_vid cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/weread/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasWereadSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://weread.qq.com' });\n  return cookies.some(c => c.name === 'wr_vid' && c.value);\n}\n\nasync function verifyWereadIdentity(page) {\n  if (!await hasWereadSessionCookie(page)) {\n    throw new AuthRequiredError('weread.qq.com', 'WeRead wr_vid cookie missing');\n  }\n  await page.goto('https://weread.qq.com/');\n  await page.wait(2);\n  const result = await page.evaluate(`(async () => {\n    try {\n      const wrVid = (document.cookie.split('; ').find(c => c.startsWith('wr_vid=')) || '').split('=')[1] || '';\n      if (!wrVid) {\n        return { kind: 'auth', detail: 'WeRead wr_vid cookie absent in document.cookie' };\n      }\n      const res = await fetch('/web/user', { credentials: 'include', headers: { 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'WeRead /web/user HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (d && d.errCode && d.errCode !== 0) {\n        return { kind: 'auth', detail: 'WeRead /web/user errCode=' + d.errCode };\n      }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread/auth.js#L1-L29","documentation":"verifyWereadIdentity in clis/weread/auth.js throws AuthRequiredError when the browser page's cookies for https://weread.qq.com contain no non-empty wr_vid cookie — WeRead's login session identifier. The library requires this cookie to prove the user is logged in before any WeRead command runs.","triggerScenarios":"hasWereadSessionCookie(page) returns false because no wr_vid cookie exists in the controlled Chrome profile — the user never logged in to weread.qq.com, the session expired and WeRead cleared the cookie, or the wrong browser profile is attached.","commonSituations":"Fresh machine/profile where the user never logged in; WeRead logged the session out; cookie cleared by browser cleanup or incognito mode; pointing the CLI at a different Chrome profile than the one with the WeRead login.","solutions":["Open https://weread.qq.com/ in the attached Chrome browser and log in with your WeChat/WeRead account.","Re-run the command after confirming wr_vid exists (DevTools > Application > Cookies for weread.qq.com).","Ensure the CLI is using the correct Chrome profile/directory that holds the login.","If cookies are being cleared, disable auto-clear-on-exit for weread.qq.com or use a persistent (non-incognito) profile."],"exampleFix":"// before: running commands with no login\n$ opencli weread shelf\nAuthRequiredError: WeRead wr_vid cookie missing\n// after: log in first\n$ opencli weread login   # opens https://weread.qq.com/, log in with WeChat\n$ opencli weread shelf","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://weread.qq.com' });\nif (!cookies.some(c => c.name === 'wr_vid' && c.value)) {\n  console.error('Not logged in to WeRead — run the login command first.');\n}","typeGuard":null,"tryCatchPattern":"try { await wereadCommand(args); } catch (e) {\n  if (e instanceof AuthRequiredError || /wr_vid cookie missing/.test(e.message)) {\n    console.error('Run `opencli weread login` and log in at weread.qq.com in the attached browser.');\n  } else throw e;\n}","preventionTips":["Log in to weread.qq.com before running WeRead commands","Use a persistent Chrome profile, never incognito","Check wr_vid in DevTools > Application > Cookies when in doubt","Point the CLI at the profile that actually holds the login"],"tags":["auth","cookies","weread","login"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}