{"record":{"id":"65b1386e1c5a865d","repo":"jackwener/OpenCLI","slug":"suno-clerk-session-client-cookie-missing","errorCode":null,"errorMessage":"Suno Clerk __session/__client cookie missing","messagePattern":"Suno Clerk __session/__client cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/suno/auth.js","lineNumber":14,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasSunoClerkCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://clerk.suno.com' });\n  // Clerk sets __client for anonymous sessions too; __session (the session JWT)\n  // is present only when authenticated, so gate on it to avoid navigating away\n  // mid-login.\n  return cookies.some(c => c.name === '__session' && c.value);\n}\n\nasync function verifySunoIdentity(page) {\n  if (!await hasSunoClerkCookie(page)) {\n    throw new AuthRequiredError('suno.com', 'Suno Clerk __session/__client cookie missing');\n  }\n  await page.goto('https://suno.com/');\n  await page.wait(2);\n  const probe = await page.evaluate(`(async () => {\n    try {\n      const r = await fetch('https://clerk.suno.com/v1/client?_clerk_js_version=5', {\n        credentials: 'include',\n        headers: { Accept: 'application/json' },\n      });\n      if (r.status === 401 || r.status === 403) {\n        return { kind: 'auth', detail: 'clerk.suno.com /v1/client HTTP ' + r.status };\n      }\n      if (!r.ok) return { kind: 'http', httpStatus: r.status };\n      const d = await r.json();\n      const sessions = d?.response?.sessions || [];\n      if (!Array.isArray(sessions) || sessions.length === 0) {\n        return { kind: 'auth', detail: 'clerk.suno.com sessions=[] — anonymous' };\n      }","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/suno/auth.js#L1-L32","documentation":"verifySunoIdentity() checks the browser's cookie jar for a non-empty Clerk `__session` cookie before probing Suno's identity API. Clerk only sets `__session` (the session JWT) once you are actually authenticated; `__client` alone just marks an anonymous visitor. If the cookie is missing the library throws AuthRequiredError for suno.com, telling you to log in first.","triggerScenarios":"Calling `opencli suno whoami`/auth verify (or any suno command that calls verifySunoIdentity) while the persistent browser profile for suno.com has no non-empty `__session` cookie — i.e. never logged in, logged out, or the Clerk session expired/was revoked.","commonSituations":"Fresh machine or wiped browser profile; Suno/Clerk session expired (JWT TTL elapsed); using a profile that only ever reached the login page; cookie cleared by privacy settings or a concurrent process navigating away mid-login.","solutions":["Run the site's login flow (loginUrl https://suno.com/?sign-in=true) and complete sign-in in the persistent browser","Re-run the command after login completes","If it persists, clear suno.com/clerk.suno.com cookies and log in again — a stale Clerk state can block issuance of a fresh __session","Check that the browser profile used is the same one opencli persists (not an incognito/isolated context)"],"exampleFix":"// before (no session)\nawait cli('suno', 'whoami'); // -> AuthRequiredError: Suno Clerk __session/__client cookie missing\n// after\nawait cli('suno', 'login');   // complete interactive sign-in\nawait cli('suno', 'whoami');","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://clerk.suno.com' });\nif (!cookies.some(c => c.name === '__session' && c.value)) {\n  await cli('suno', 'login'); // obtain a session before running commands\n}","typeGuard":"function hasSessionCookie(cookies) {\n  return Array.isArray(cookies) && cookies.some(c => c.name === '__session' && !!c.value);\n}","tryCatchPattern":"try {\n  await cli('suno', 'whoami');\n} catch (e) {\n  if (e.name === 'AuthRequiredError' || /cookie missing/.test(e.message)) {\n    await cli('suno', 'login');\n    return cli('suno', 'whoami');\n  }\n  throw e;\n}","preventionTips":["Run the login flow once per machine/profile before scripting suno commands","Check session freshness periodically — Clerk JWTs expire","Don't share/wipe the persistent browser profile while commands run","Gate automation on a quick cookie check like hasSunoClerkCookie before heavy work"],"tags":["auth","cookie","clerk","suno"],"backgroundTag":"auth-session-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}