jackwener/OpenCLI · error · AuthRequiredError
Could not detect a logged-in GitHub account
Error message
Could not detect a logged-in GitHub account
What it means
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.
Source
Thrown at clis/github/auth.js:21
async function hasGithubSessionCookies(page) {
const cookies = await page.getCookies({ url: 'https://github.com' });
const names = new Set(cookies.map(cookie => cookie.name));
return names.has('user_session') || names.has('dotcom_user') || names.has('logged_in');
}
async function verifyGithubIdentity(page) {
await page.goto('https://github.com/settings/profile');
await page.wait(1);
const identity = await page.evaluate(`() => {
const meta = (name) => document.querySelector('meta[name="' + name + '"]')?.getAttribute('content') || '';
const username = meta('octolytics-actor-login');
const id = meta('octolytics-actor-id');
const name = document.querySelector('input#user_profile_name')?.value || '';
return { username, id, name, url: location.href };
}`);
if (!identity?.username || /\/login(?:\?|$)/.test(String(identity?.url ?? ''))) {
throw new AuthRequiredError('github.com', 'Could not detect a logged-in GitHub account');
}
return {
id: identity.id || '',
username: identity.username,
name: identity.name || '',
url: `https://github.com/${identity.username}`,
};
}
registerSiteAuthCommands({
site: 'github',
domain: 'github.com',
loginUrl: 'https://github.com/login',
columns: ['id', 'username', 'name', 'url'],
quickCheck: hasGithubSessionCookies,
verify: verifyGithubIdentity,
poll: async (page) => {
if (!await hasGithubSessionCookies(page)) {View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
const identity = await verifyGithubIdentity(page); // throws if not logged in
// after
try {
const identity = await verifyGithubIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError) {
await page.goto('https://github.com/login'); // let user log in, then retry
const identity = await verifyGithubIdentity(page);
} else throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const cookies = await page.cookies('https://github.com');
if (!cookies.some(c => c.name.startsWith('logged_in') || c.name === 'user_session')) {
throw new Error('No GitHub session — log in before running commands');
} Type guard
function isGithubIdentity(v) {
return !!v && typeof v.username === 'string' && v.username.length > 0 && !/\/login(?:\?|$)/.test(String(v.url ?? ''));
} Try / catch
try {
const identity = await verifyGithubIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError) {
await openBrowserTo('https://github.com/login'); // complete login, then retry
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Ke lianjia_token cookie missing — anonymous
- Not logged into x.com (no ct0 cookie)
- Browser session required for bilibili follow
- Browser session required for bilibili following
- 未获取到课程列表
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2dbd041928658c7b.
Report an issue: GitHub.