{"record":{"id":"1ec27c9411886724","repo":"jackwener/OpenCLI","slug":"wechat-channels-sessionid-cookie-missing","errorCode":null,"errorMessage":"WeChat Channels sessionid cookie missing","messagePattern":"WeChat Channels sessionid cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/wechat-channels/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasWechatChannelsSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://channels.weixin.qq.com' });\n  return cookies.some(c => c.name === 'sessionid' && c.value);\n}\n\nasync function verifyWechatChannelsIdentity(page) {\n  if (!await hasWechatChannelsSessionCookie(page)) {\n    throw new AuthRequiredError('channels.weixin.qq.com', 'WeChat Channels sessionid cookie missing');\n  }\n  await page.goto('https://channels.weixin.qq.com/platform');\n  await page.wait(2);\n  const probe = await page.evaluate(`(async () => {\n    try {\n      if (/login\\\\.html/.test(location.href)) {\n        return { kind: 'auth', detail: 'WeChat Channels platform redirected to login.html' };\n      }\n      const r = await fetch('/cgi-bin/mmfinderassistant-bin/auth/auth_data', {\n        method: 'POST',\n        credentials: 'include',\n        headers: { 'Content-Type': 'application/json' },\n        body: '{}',\n      });\n      if (!r.ok) return { kind: 'http', httpStatus: r.status };\n      const d = await r.json();\n      if (!d || d.base_resp?.ret !== 0) {\n        return { kind: 'auth', detail: 'WeChat Channels auth_data base_resp.ret=' + String(d?.base_resp?.ret) };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wechat-channels/auth.js#L1-L29","documentation":"verifyWechatChannelsIdentity first checks the browser profile for a non-empty `sessionid` cookie on channels.weixin.qq.com (hasWechatChannelsSessionCookie). Without it the WeChat Channels platform calls cannot authenticate, so an AuthRequiredError is thrown directing the user to log in via the site's auth flow.","triggerScenarios":"Running any wechat-channels command before ever logging in; the saved browser profile was cleared or is fresh; the session expired and WeChat deleted the sessionid cookie; cookies exist for a different domain (e.g. qq.com main site) but not channels.weixin.qq.com.","commonSituations":"First-time setup; container/incognito profile without stored cookies; WeChat revoked the session server-side; switching machines or browser profiles.","solutions":["Run the site's login flow: open https://channels.weixin.qq.com/login.html?from=assistant and scan the QR code with the WeChat app.","Re-check cookies after login: a non-empty sessionid cookie must exist for channels.weixin.qq.com.","If using a persistent profile, point the tool at the profile where you actually logged in.","If the session expired repeatedly, log in again shortly before running commands.","Verify system clock is sane — skewed clocks can cause servers to invalidate sessions."],"exampleFix":"// before (no login)\nwechat-channels list\n// after\nwechat-channels login   # scan QR in WeChat app\nwechat-channels list","handlingStrategy":"validation","validationCode":"// Pre-flight: verify session cookie before invoking any wechat-channels command\nconst cookies = await page.getCookies({ url: 'https://channels.weixin.qq.com' });\nif (!cookies.some(c => c.name === 'sessionid' && c.value)) {\n  throw new Error('Not logged in — run wechat-channels login first');\n}","typeGuard":"function hasSession(cookies) { return Array.isArray(cookies) && cookies.some(c => c.name === 'sessionid' && !!c.value); }","tryCatchPattern":"try {\n  await wechatChannelsCommand(args);\n} catch (e) {\n  if (e instanceof AuthRequiredError || /sessionid cookie missing/.test(e.message)) {\n    await runLoginFlow(); // open login.html, await QR scan\n    await wechatChannelsCommand(args);\n  } else throw e;\n}","preventionTips":["Run the login flow before scripted operations; keep the profile persistent","Re-login proactively when sessions are old","Check the cookie exists for the exact domain channels.weixin.qq.com","Don't share/incognito profiles for automation sessions"],"tags":["auth","cookies","wechat","session"],"backgroundTag":"auth-required-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}