{"record":{"id":"008b5198bd09ea48","repo":"mastra-ai/mastra","slug":"not-logged-in","errorCode":null,"errorMessage":"Not logged in","messagePattern":"Not logged in","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/auth/credentials.ts","lineNumber":75,"sourceCode":"    await unlink(CREDENTIALS_FILE);\n  } catch {\n    // file doesn't exist, that's fine\n  }\n}\n\nexport async function getCurrentOrgId(): Promise<string | null> {\n  // CI/CD headless path\n  const envOrgId = process.env.MASTRA_ORG_ID;\n  if (envOrgId) return envOrgId;\n\n  const creds = await loadCredentials();\n  if (!creds) return null;\n  return creds.currentOrgId ?? creds.organizationId;\n}\n\nexport async function setCurrentOrgId(orgId: string): Promise<void> {\n  const creds = await loadCredentials();\n  if (!creds) throw new Error('Not logged in');\n  creds.currentOrgId = orgId;\n  await saveCredentials(creds);\n}\n\nfunction isWSL(): boolean {\n  if (process.platform !== 'linux') return false;\n  try {\n    // WSL kernels contain \"microsoft\" or \"WSL\" in the version string\n    return /microsoft|wsl/i.test(release()) || /microsoft|wsl/i.test(readFileSync('/proc/version', 'utf-8'));\n  } catch {\n    return false;\n  }\n}\n\nfunction openBrowser(url: string) {\n  // Use execFileSync (shell: false) to avoid shell-injection via the URL.\n  if (process.platform === 'darwin') {\n    execFileSync('open', [url]);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/auth/credentials.ts#L57-L93","documentation":"setCurrentOrgId persists the selected organization into stored credentials. It first loads credentials; if none exist (the user never logged in), it throws 'Not logged in' because there is no credential object to update. Called by resolveCurrentOrg and switchOrgAction during org selection.","triggerScenarios":"`mastra auth orgs <orgId>` (switchOrgAction) or any command resolving the current org calls setCurrentOrgId while loadCredentials() returns null — no credentials file on disk.","commonSituations":"Running org-switch on a fresh machine; running before ever executing `mastra auth login`; CI environments without credentials or MASTRA_API_TOKEN; credentials file removed between commands.","solutions":["Run `mastra auth login` first, then switch orgs with `mastra auth orgs`.","Set MASTRA_API_TOKEN if operating non-interactively (org selection then handled per command).","Verify the credentials file exists under the expected home directory."],"exampleFix":"// before\nmastra auth orgs org_abc123  # -> Error: Not logged in\n// after\nmastra auth login\nmastra auth orgs org_abc123","handlingStrategy":"validation","validationCode":"const { loadCredentials } = await import('./credentials.js');\nconst creds = await loadCredentials();\nif (!creds) {\n  throw new Error('Not logged in: run `mastra auth login` before switching orgs');\n}\nawait setCurrentOrgId(orgId);","typeGuard":null,"tryCatchPattern":"try {\n  await setCurrentOrgId(orgId);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Not logged in') {\n    console.error('Run `mastra auth login` first.');\n    return;\n  }\n  throw err;\n}","preventionTips":["Always run `mastra auth login` before org management commands on a new machine.","Guard scripts with a credential-existence check before org switching.","Use MASTRA_API_TOKEN in CI instead of mutating stored org state."],"tags":["cli","auth","credentials","org"],"backgroundTag":"missing-credentials","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}