{"record":{"id":"f900ba7e110fa654","repo":"jackwener/OpenCLI","slug":"result-detail-f900ba","errorCode":null,"errorMessage":"${result.detail}","messagePattern":"\\$\\{result\\.detail\\}","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/instagram/auth.js","lineNumber":37,"sourceCode":"      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) {\n        return { kind: 'auth', detail: 'Instagram /users/info returned no pk — session likely expired' };\n      }\n      return { ok: true, user_id: String(user.pk), username: String(user.username || ''), full_name: String(user.full_name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('www.instagram.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from Instagram /users/info`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Instagram whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Instagram probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, username: result.username, full_name: result.full_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'instagram',\n  domain: 'instagram.com',\n  loginUrl: 'https://www.instagram.com/accounts/login/',\n  columns: ['user_id', 'username', 'full_name'],\n  quickCheck: hasInstagramSessionCookie,\n  verify: verifyInstagramIdentity,\n  poll: async (page) => {\n    if (!await hasInstagramSessionCookie(page)) {\n      throw new AuthRequiredError('www.instagram.com', 'Waiting for Instagram sessionid cookie');\n    }\n    return verifyInstagramIdentity(page);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/auth.js#L19-L55","documentation":"An AuthRequiredError raised when the in-page whoami probe reports kind:'auth', meaning Instagram's /users/info endpoint returned 401/403, the ds_user_id cookie was missing, or the response had no user pk (session likely expired). The library surfaces the inner detail (result.detail) as the auth error so the user knows login is required again. It is distinct from generic HTTP failures, which go through error 1935.","triggerScenarios":"page.evaluate whoami probe inside verifyInstagramIdentity returns {kind:'auth', detail}: ds_user_id cookie absent from document.cookie; fetch of /api/v1/users/<uid>/info/ with credentials:'include' responds 401 or 403; or the JSON response lacks user.pk.","commonSituations":"Session expired between login and command execution; Instagram invalidated the session server-side (password change, security checkpoint); cookies exist but are stale so the API rejects them; ds_user_id cookie blocked by browser cookie settings.","solutions":["Re-run the Instagram login flow to obtain a fresh session","If Instagram shows a security checkpoint ('suspicious login'), complete it in the browser, then retry","Verify ds_user_id and sessionid cookies are both present for instagram.com after login","Avoid running many automated requests that could trigger Instagram's abuse detection; slow down and retry later"],"exampleFix":"// before: stale session\n$ opencli instagram whoami\nError: Instagram /users/info HTTP 403\n\n// after: re-authenticate\n$ opencli instagram auth login\n$ opencli instagram whoami","handlingStrategy":"try-catch","validationCode":"// verify the session is fresh before running commands\nconst cookies = await page.getCookies({ url: 'https://www.instagram.com' });\nif (!cookies.some(c => c.name === 'sessionid' && c.value) ||\n    !cookies.some(c => c.name === 'ds_user_id' && c.value)) {\n  await runInstagramLogin();\n}","typeGuard":"function hasFreshInstagramCookies(cookies) {\n  const names = new Set((cookies ?? []).filter(c => c.value).map(c => c.name));\n  return names.has('sessionid') && names.has('ds_user_id');\n}","tryCatchPattern":"try {\n  await instagramWhoami();\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await runInstagramLogin();      // session expired or rejected\n    return instagramWhoami();\n  }\n  throw e;\n}","preventionTips":["Re-login whenever the underlying session may have expired (long gaps, password changes)","Complete any Instagram security checkpoints in the browser before automating","Keep both sessionid and ds_user_id cookies present; absence of either signals a stale session","Don't share one account across many automation sessions — it invites server-side invalidation"],"tags":["authentication","session-expired","instagram","cookies"],"backgroundTag":"instagram-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}