{"record":{"id":"2d45ee139527d0cf","repo":"jackwener/OpenCLI","slug":"twitter-x-auth-cookies-are-missing","errorCode":null,"errorMessage":"Twitter/X auth cookies are missing","messagePattern":"Twitter/X auth cookies are missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/twitter/auth.js","lineNumber":56,"sourceCode":" * account for a few seconds, so a single read misreports it (#2252); trust\n * the handle only once it holds across three polls.\n */\nasync function readSettledScreenName(page) {\n  const samples = [];\n  for (let poll = 0; poll < SCREEN_NAME_POLLS; poll += 1) {\n    samples.push(await readScreenName(page));\n    if (poll < SCREEN_NAME_POLLS - 1) {\n      await page.sleep(SCREEN_NAME_POLL_SECONDS);\n    }\n  }\n  const tail = samples.slice(-SCREEN_NAME_AGREEMENTS);\n  const username = tail[0] || '';\n  return username && tail.every((sample) => sample === username) ? username : '';\n}\n\nasync function verifyTwitterIdentity(page, { phase } = {}) {\n  if (!await hasTwitterSessionCookies(page)) {\n    throw new AuthRequiredError('x.com', 'Twitter/X auth cookies are missing');\n  }\n  await page.goto('https://x.com/home');\n  await page.wait({ selector: '[data-testid=\"primaryColumn\"]' }).catch(() => { });\n  // Login polls repeat every ~2s; they keep the single read and skip the #2252 settle loop.\n  const username = phase === 'poll'\n    ? await readScreenName(page)\n    : await readSettledScreenName(page);\n  if (!username) {\n    throw new AuthRequiredError('x.com', 'Could not detect the logged-in Twitter/X profile link');\n  }\n  return { username, url: `https://x.com/${username}` };\n}\n\nregisterSiteAuthCommands({\n  site: 'twitter',\n  domain: 'x.com',\n  loginUrl: 'https://x.com/i/flow/login',\n  columns: ['username', 'url'],","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/auth.js#L38-L74","documentation":"verifyTwitterIdentity first checks hasTwitterSessionCookies(page); if the auth_tweet_cookie/auth Cookies are absent it throws AuthRequiredError('x.com', 'Twitter/X auth cookies are missing'). This is a deliberate auth-gate: identity verification cannot proceed without a logged-in session, so the CLI signals that the user must log in to x.com in the controlled browser.","triggerScenarios":"Calling a twitter command that requires identity verification when the browser has no x.com session cookies — fresh profile, cookies cleared, or logged out of x.com.","commonSituations":"Running the CLI with a brand-new automation browser profile, after clearing cookies/site data, after x.com invalidated the session (password change, security logout), or pointing the CLI at the wrong browser profile directory.","solutions":["Run the x.com login flow (auth login for the twitter site) and complete login in the browser window.","Verify the browser profile the CLI uses is the one where you actually logged in.","Confirm cookies are not being wiped between runs (e.g. incognito mode or cleanup scripts).","Manually open x.com in the controlled browser and confirm you stay logged in."],"exampleFix":"// before\nawait cli.run('twitter whoami');\n// after\nif (!(await hasSessionCookies())) {\n  await cli.run('auth login x.com'); // complete login interactively\n}\nawait cli.run('twitter whoami');","handlingStrategy":"try-catch","validationCode":"// before invoking identity-requiring commands\nconst cookies = await getCookies('x.com');\nif (!cookies.some((c) => c.name === 'auth_token')) {\n  await cli.run('auth login x.com');\n}","typeGuard":"function hasSessionCookie(cookies) {\n  return Array.isArray(cookies) && cookies.some((c) => c.name === 'auth_token' && c.value);\n}","tryCatchPattern":"try {\n  await cli.run('twitter whoami');\n} catch (e) {\n  if (/auth cookies are missing/.test(e.message)) {\n    await cli.run('auth login x.com');\n    return cli.run('twitter whoami');\n  }\n  throw e;\n}","preventionTips":["Use a persistent browser profile so cookies survive restarts","Never run cookie-dependent commands in incognito profiles","Re-login after x.com forces a session invalidation (password change)","Check cookie presence proactively before identity-requiring commands"],"tags":["authentication","cookies","x-com"],"backgroundTag":"missing-auth-cookies","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}