{"record":{"id":"40a0947b43f39192","repo":"jackwener/OpenCLI","slug":"toutiao-sessionid-cookie-missing","errorCode":null,"errorMessage":"Toutiao sessionid cookie missing","messagePattern":"Toutiao sessionid cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/toutiao/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasToutiaoSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://mp.toutiao.com' });\n  return cookies.some(c => c.name === 'sessionid' && c.value);\n}\n\nasync function verifyToutiaoIdentity(page) {\n  if (!await hasToutiaoSessionCookie(page)) {\n    throw new AuthRequiredError('toutiao.com', 'Toutiao sessionid cookie missing');\n  }\n  await page.goto('https://mp.toutiao.com/');\n  await page.wait(2);\n  const probe = await page.evaluate(`\n    (() => {\n      if (/\\\\/auth\\\\/page\\\\/login/.test(location.href)) {\n        return { kind: 'auth', detail: 'mp.toutiao.com redirected to /auth/page/login — anonymous' };\n      }\n      let userId = '', nickname = '';\n      try {\n        const seen = new Set();\n        const stack = [window.__INITIAL_STATE__, window.__REDUX_STATE__, window.__SSR_DATA__].filter(Boolean);\n        while (stack.length) {\n          const node = stack.pop();\n          if (!node || typeof node !== 'object' || seen.has(node)) continue;\n          seen.add(node);\n          if (Array.isArray(node)) { stack.push(...node); continue; }\n          const u = node.userInfo || node.user || node.currentUser || node.userBase;","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/auth.js#L1-L29","documentation":"AuthRequiredError thrown by verifyToutiaoIdentity when the browser session has no non-empty `sessionid` cookie for https://mp.toutiao.com. That cookie is the credential proving a logged-in creator account; without it identity verification cannot proceed.","triggerScenarios":"Invoking toutiao auth verify (or any flow calling verifyToutiaoIdentity) when page.getCookies({url:'https://mp.toutiao.com'}) returns no cookie named `sessionid` with a truthy value — never logged in, logged out, or cookies cleared.","commonSituations":"Running the command before completing the browser login flow; Toutiao expired/revoked the session server-side; headless browser launched with a fresh/incognito profile lacking stored cookies; browser settings or cleanup purged cookies.","solutions":["Run the toutiao auth login flow and complete login at https://mp.toutiao.com/auth/page/login, then re-verify.","Open mp.toutiao.com manually in the same browser profile and confirm you stay logged in.","Point the tool at the persistent profile that actually holds the sessionid cookie; avoid incognito/ephemeral contexts.","If the session expired, log in again — the cookie cannot be recreated client-side.","Check system clock accuracy; skewed clocks cause cookies to be dropped as expired."],"exampleFix":"// before: fresh ephemeral context with no cookies\nconst page = await browser.newPage();\nawait verifyToutiaoIdentity(page); // throws AuthRequiredError\n// after: reuse a persistent logged-in profile\nconst context = await browser.launchPersistentContext(userDataDir, { headless: false });\nconst page = await context.newPage();\nawait toutiaoLogin(page); // ensures sessionid cookie exists\nawait verifyToutiaoIdentity(page);","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://mp.toutiao.com' });\nconst session = cookies.find(c => c.name === 'sessionid');\nif (!session || !session.value) {\n  throw new Error('No mp.toutiao.com sessionid cookie — run the toutiao login flow first');\n}","typeGuard":"function hasToutiaoSession(cookies) {\n  return Array.isArray(cookies) && cookies.some(\n    c => c && c.name === 'sessionid' && typeof c.value === 'string' && c.value.length > 0,\n  );\n}","tryCatchPattern":"try {\n  const identity = await toutiaoAuthVerify(page);\n} catch (err) {\n  if (err.name === 'AuthRequiredError' && err.message.includes('sessionid cookie missing')) {\n    await toutiaoAuthLogin(page);\n    return toutiaoAuthVerify(page);\n  }\n  throw err;\n}","preventionTips":["Always run the toutiao login flow before verify/scraper commands; never use incognito or ephemeral profiles.","Use a persistent user-data-dir so the sessionid cookie survives between runs.","Preflight with hasToutiaoSessionCookie before any mp.toutiao.com command.","Re-login when the session ages out — sessionid expires server-side even while still stored.","Keep the system clock accurate so cookies are not discarded as expired."],"tags":["auth","session","cookie","toutiao"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}