{"record":{"id":"42d5f26f22f573ef","repo":"jackwener/OpenCLI","slug":"instagram-sessionid-cookie-missing","errorCode":null,"errorMessage":"Instagram sessionid cookie missing","messagePattern":"Instagram sessionid cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/instagram/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasInstagramSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.instagram.com' });\n  return cookies.some(c => c.name === 'sessionid' && c.value);\n}\n\nasync function verifyInstagramIdentity(page) {\n  if (!await hasInstagramSessionCookie(page)) {\n    throw new AuthRequiredError('www.instagram.com', 'Instagram sessionid cookie missing');\n  }\n  await page.goto('https://www.instagram.com/');\n  await page.wait(2);\n  const result = await page.evaluate(`(async () => {\n    try {\n      const uid = (document.cookie.split('; ').find(c => c.startsWith('ds_user_id=')) || '').split('=')[1] || '';\n      if (!uid) return { kind: 'auth', detail: 'Instagram ds_user_id cookie missing' };\n      const r = await fetch('/api/v1/users/' + uid + '/info/', {\n        credentials: 'include',\n        headers: { 'X-IG-App-ID': '936619743392459', 'Accept': 'application/json' },\n      });\n      if (r.status === 401 || r.status === 403) {\n        return { kind: 'auth', detail: 'Instagram /users/info HTTP ' + r.status };\n      }\n      if (!r.ok) return { kind: 'http', httpStatus: r.status };\n      const d = await r.json();\n      const user = d?.user;\n      if (!user || !user.pk) {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/auth.js#L1-L29","documentation":"An AuthRequiredError thrown at the start of verifyInstagramIdentity when the browser page has no non-empty `sessionid` cookie for www.instagram.com. The library requires this cookie as a fast precondition before probing Instagram's whoami API, since every authenticated Instagram API call depends on it. It means you are not logged in (or the cookie jar was lost) and the command cannot proceed.","triggerScenarios":"Any instagram CLI command that calls verifyInstagramIdentity (login verify, poll, or site-auth flows) when page.getCookies({url:'https://www.instagram.com'}) contains no cookie named 'sessionid' with a non-empty value.","commonSituations":"Never having run the Instagram login command; the persistent browser profile was cleared or recreated; Instagram expired/invalidated the sessionid so it was dropped; running in a fresh CI/container without the cookie store.","solutions":["Run the Instagram login command and complete the login in the opened browser window so sessionid is set","Confirm you actually finished the login (including any 2FA challenge) before the browser closes","If cookies were cleared, log in again to repopulate the profile's cookie store","Check that you are using the same browser profile/user-data-dir the CLI is configured with"],"exampleFix":"// before\n$ opencli instagram whoami\nError: Instagram sessionid cookie missing\n\n// after\n$ opencli instagram auth login\n$ opencli instagram whoami","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.instagram.com' });\nconst hasSession = cookies.some(c => c.name === 'sessionid' && c.value);\nif (!hasSession) {\n  await runInstagramLogin(); // authenticate before proceeding\n}","typeGuard":"function isLoggedInToInstagram(cookies) {\n  return Array.isArray(cookies) &&\n    cookies.some(c => c.name === 'sessionid' && typeof c.value === 'string' && c.value !== '');\n}","tryCatchPattern":"try {\n  await instagramCommand();\n} catch (e) {\n  if (e instanceof AuthRequiredError || /sessionid cookie missing/.test(e.message)) {\n    await runInstagramLogin();\n    return instagramCommand();\n  }\n  throw e;\n}","preventionTips":["Run a login/verify step as a precondition for any Instagram command","Use a persistent browser profile so cookies survive restarts","Check cookie presence (quickCheck) before every batch run","After clearing browser data or switching profiles, log in again before running commands"],"tags":["authentication","cookies","instagram","auth-required"],"backgroundTag":"instagram-session-not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}