{"record":{"id":"5d222e7fb32dff1a","repo":"jackwener/OpenCLI","slug":"auth-5d222e","errorCode":null,"errorMessage":"auth","messagePattern":"auth","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/youtube/auth.js","lineNumber":36,"sourceCode":"      const cfg = (typeof window !== 'undefined' && window.ytcfg && typeof window.ytcfg.get === 'function') ? window.ytcfg : null;\n      // ytcfg LOGGED_IN is the reliable signed-in signal; the avatar button is a fallback.\n      const loggedIn = !!(cfg && cfg.get('LOGGED_IN') === true) || !!document.querySelector('#avatar-btn');\n      if (!loggedIn) {\n        return { kind: 'auth', detail: 'YouTube ytcfg LOGGED_IN not true and no avatar — not signed in' };\n      }\n      // Name is best-effort: YouTube's masthead avatar exposes a generic\n      // \"Account menu\" aria-label, so the channel name is often unavailable\n      // without opening the menu. Surface it when present, else leave empty.\n      let name = '';\n      try { const ctx = cfg && cfg.get('INNERTUBE_CONTEXT'); name = (ctx && ctx.user && ctx.user.identityName) || ''; } catch {}\n      if (!name) {\n        const aria = (document.querySelector('#avatar-btn')?.getAttribute('aria-label') || '').trim();\n        if (aria && !/^account menu$/i.test(aria)) name = aria;\n      }\n      return { ok: true, name: String(name || '') };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('www.youtube.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected YouTube probe: ${JSON.stringify(probe)}`);\n  return { name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'youtube',\n  domain: 'www.youtube.com',\n  loginUrl: 'https://accounts.google.com/ServiceLogin?service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2F',\n  columns: ['name'],\n  quickCheck: hasGoogleSessionCookie,\n  verify: verifyYoutubeIdentity,\n  poll: async (page) => {\n    if (!await hasGoogleSessionCookie(page)) {\n      throw new AuthRequiredError('www.youtube.com', 'Waiting for Google session cookies');\n    }\n    return verifyYoutubeIdentity(page);\n  },\n});","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/youtube/auth.js#L18-L54","documentation":"After the cookie check, the in-page probe is evaluated on youtube.com. If the probe reports kind === 'auth', the page itself signaled the user is not authenticated (e.g. redirected to a sign-in page), so AuthRequiredError('www.youtube.com', probe.detail) is thrown with the page-reported detail.","triggerScenarios":"Google cookies exist but YouTube still treats the session as signed out — expired/invalid cookies, YouTube rejecting the session, anti-bot interstitials, or the page redirected to a consent/login screen before probing.","commonSituations":"Stale SID/SAPISID cookies that no longer authenticate; Google security challenges (suspicious activity); consent/ToS page blocking the session; cookies from a different Google account without YouTube access.","solutions":["Re-run the login flow to refresh Google/YouTube session cookies","Complete any Google security or consent challenges in the automated browser once manually","Check probe.detail in the error for the page-reported reason","Wait and retry if YouTube is showing a transient interstitial"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const cookies = await getCookies('https://www.youtube.com');\nif (!new Set(cookies.map(c => c.name)).has('SAPISID')) {\n  await runLoginFlow('youtube');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli.youtube.whoami();\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    console.error('YouTube session rejected:', e.message);\n    await cli.login('youtube'); // refresh cookies / clear challenges\n  } else throw e;\n}","preventionTips":["Refresh cookies proactively; Google sessions expire","Complete security/consent challenges manually once in the automated browser","Keep the logged-in Google account active for YouTube","Read the wrapped detail for the page-reported reason"],"tags":["auth","cookies","youtube"],"backgroundTag":"missing-auth-cookies","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}