{"record":{"id":"6f872deb41dbe772","repo":"jackwener/OpenCLI","slug":"waiting-for-toutiao-sessionid-cookie","errorCode":null,"errorMessage":"Waiting for Toutiao sessionid cookie","messagePattern":"Waiting for Toutiao sessionid cookie","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"warning","filePath":"clis/toutiao/auth.js","lineNumber":66,"sourceCode":"      }\n      return { ok: true, user_id: userId, nickname };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('toutiao.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, nickname: probe.nickname };\n}\n\nregisterSiteAuthCommands({\n  site: 'toutiao',\n  domain: 'toutiao.com',\n  loginUrl: 'https://mp.toutiao.com/auth/page/login',\n  columns: ['user_id', 'nickname'],\n  quickCheck: hasToutiaoSessionCookie,\n  verify: verifyToutiaoIdentity,\n  poll: async (page) => {\n    if (!await hasToutiaoSessionCookie(page)) {\n      throw new AuthRequiredError('toutiao.com', 'Waiting for Toutiao sessionid cookie');\n    }\n    return verifyToutiaoIdentity(page);\n  },\n});\n","sourceCodeStart":48,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/auth.js#L48-L71","documentation":"AuthRequiredError thrown by the toutiao site-auth poll handler on each poll tick while waiting for the user to finish login: if the sessionid cookie is not yet present, the poll throws instead of returning an identity. It signals 'login not finished yet' during the interactive polling loop, not a hard failure.","triggerScenarios":"During the toutiao auth login/poll flow, a poll iteration runs before login completes — getCookies for https://mp.toutiao.com still has no non-empty sessionid cookie.","commonSituations":"User is slow entering credentials/2FA in the opened login window; a CAPTCHA or QR-code scan is pending; the user closed the login tab without logging in; the poll window is too short for the chosen login method.","solutions":["Complete the login at https://mp.toutiao.com/auth/page/login in the browser window before the poll window expires; the next poll then succeeds.","If the poll loop aborts on this throw, restart toutiao auth login and finish login promptly.","Handle AuthRequiredError in your polling wrapper and keep polling until a deadline instead of aborting on the first throw.","Clear any CAPTCHA/interstitials quickly, or log in manually beforehand in the same profile so the cookie already exists.","Increase the poll timeout/deadline if your login path (2FA, SMS, QR) routinely exceeds it."],"exampleFix":"// before: caller aborts on the first poll throw\nawait pollUntil(() => authPoll(page), timeout);\n// after: tolerate 'waiting' during login\nawait pollUntil(async () => {\n  try {\n    return await authPoll(page);\n  } catch (e) {\n    if (e.name === 'AuthRequiredError' && /Waiting for/.test(e.message)) return false;\n    throw e;\n  }\n}, timeout);","handlingStrategy":"retry","validationCode":"// Caller-side preflight before starting the login poll\nconst deadline = Date.now() + 120_000;\nconst hasSession = async () =>\n  (await page.getCookies({ url: 'https://mp.toutiao.com' }))\n    .some(c => c.name === 'sessionid' && c.value);\nif (!(await hasSession()) && Date.now() > deadline) {\n  throw new Error('Login window expired without a sessionid cookie');\n}","typeGuard":"function isWaitingForLoginError(err) {\n  return !!err && err.name === 'AuthRequiredError' && /Waiting for Toutiao sessionid cookie/.test(err.message);\n}","tryCatchPattern":"try {\n  await toutiaoAuthLogin(page);\n} catch (err) {\n  if (isWaitingForLoginError(err)) {\n    // keep polling until the deadline instead of aborting\n    console.warn('Login not finished yet — retrying poll...');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Complete the browser login (including 2FA/CAPTCHA) promptly once the login window opens.","Set a poll deadline and keep polling on this specific error rather than aborting the flow.","Log in manually beforehand in the same persistent profile so the sessionid cookie already exists.","Don't close the login tab or browser window while the poll loop is running.","Allow extra time for QR-code/SMS login paths which routinely exceed short poll timeouts."],"tags":["auth","login-flow","polling","cookie","toutiao"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}