{"record":{"id":"2dbd041928658c7b","repo":"jackwener/OpenCLI","slug":"could-not-detect-a-logged-in-github-account","errorCode":null,"errorMessage":"Could not detect a logged-in GitHub account","messagePattern":"Could not detect a logged-in GitHub account","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/github/auth.js","lineNumber":21,"sourceCode":"\nasync function hasGithubSessionCookies(page) {\n  const cookies = await page.getCookies({ url: 'https://github.com' });\n  const names = new Set(cookies.map(cookie => cookie.name));\n  return names.has('user_session') || names.has('dotcom_user') || names.has('logged_in');\n}\n\nasync function verifyGithubIdentity(page) {\n  await page.goto('https://github.com/settings/profile');\n  await page.wait(1);\n  const identity = await page.evaluate(`() => {\n    const meta = (name) => document.querySelector('meta[name=\"' + name + '\"]')?.getAttribute('content') || '';\n    const username = meta('octolytics-actor-login');\n    const id = meta('octolytics-actor-id');\n    const name = document.querySelector('input#user_profile_name')?.value || '';\n    return { username, id, name, url: location.href };\n  }`);\n  if (!identity?.username || /\\/login(?:\\?|$)/.test(String(identity?.url ?? ''))) {\n    throw new AuthRequiredError('github.com', 'Could not detect a logged-in GitHub account');\n  }\n  return {\n    id: identity.id || '',\n    username: identity.username,\n    name: identity.name || '',\n    url: `https://github.com/${identity.username}`,\n  };\n}\n\nregisterSiteAuthCommands({\n  site: 'github',\n  domain: 'github.com',\n  loginUrl: 'https://github.com/login',\n  columns: ['id', 'username', 'name', 'url'],\n  quickCheck: hasGithubSessionCookies,\n  verify: verifyGithubIdentity,\n  poll: async (page) => {\n    if (!await hasGithubSessionCookies(page)) {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/github/auth.js#L3-L39","documentation":"verifyGithubIdentity runs JavaScript inside the browser page against github.com and reads the octolytics-actor-login meta tag to identify the logged-in user. It throws AuthRequiredError when no username can be detected or the page URL is the /login page, meaning the browser session is not authenticated to GitHub.","triggerScenarios":"The in-page probe returns identity with an empty/undefined username, or identity.url matches /\\/[ifornia](?:\\?|$)/ (i.e. GitHub redirected to the login page). Happens on any command gated behind GitHub authentication when the browser profile has no active GitHub session.","commonSituations":"Fresh browser profile / incognito context never logged into GitHub; GitHub session expired and page redirected to /login; probing a page other than github.com so the octolytics meta tags are absent; GitHub serving logged-out variant of the page.","solutions":["Open the browser session and log into github.com manually, then re-run the command","Run the site's login flow (loginUrl https://github.com/login) and wait for the poll/verify to pass","Confirm the page being evaluated is actually on github.com (meta tags only exist there)","Check that cookies were not cleared between runs; use a persistent browser profile"],"exampleFix":"// before\nconst identity = await verifyGithubIdentity(page); // throws if not logged in\n// after\ntry {\n  const identity = await verifyGithubIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await page.goto('https://github.com/login'); // let user log in, then retry\n    const identity = await verifyGithubIdentity(page);\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const cookies = await page.cookies('https://github.com');\nif (!cookies.some(c => c.name.startsWith('logged_in') || c.name === 'user_session')) {\n  throw new Error('No GitHub session — log in before running commands');\n}","typeGuard":"function isGithubIdentity(v) {\n  return !!v && typeof v.username === 'string' && v.username.length > 0 && !/\\/login(?:\\?|$)/.test(String(v.url ?? ''));\n}","tryCatchPattern":"try {\n  const identity = await verifyGithubIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await openBrowserTo('https://github.com/login'); // complete login, then retry\n  } else throw e;\n}","preventionTips":["Use a persistent browser profile that stays logged into GitHub","Probe session cookies before running gated commands","Re-auth proactively when session age is near expiry","Ensure evaluations run on a github.com origin, not other pages","Catch AuthRequiredError explicitly to trigger the login flow"],"tags":["auth","github","browser","session"],"backgroundTag":"auth-required-session-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}