{"record":{"id":"35223c7c72a17c9d","repo":"mastra-ai/mastra","slug":"no-access-to-organization-orgid-run-mastra-au","errorCode":null,"errorMessage":"No access to organization ${orgId}. Run: mastra auth orgs","messagePattern":"No access to organization (.+?)\\. Run: mastra auth orgs","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/auth/credentials.ts","lineNumber":377,"sourceCode":"  signal?.throwIfAborted();\n\n  if (options.allowLogin === false || !isInteractive()) {\n    throw new Error('Session expired. Run `mastra auth login` interactively or set MASTRA_API_TOKEN.');\n  }\n  const newCreds = await login(signal, options);\n  return newCreds.token;\n}\n\n/**\n * Validate that the user has access to the specified organization.\n * Throws if the org is not in the user's org list.\n */\nexport async function validateOrgAccess(token: string, orgId: string): Promise<void> {\n  const { fetchOrgs } = await import('./api.js');\n  const orgs = await fetchOrgs(token);\n  const hasAccess = orgs.some(o => o.id === orgId);\n  if (!hasAccess) {\n    throw new Error(`No access to organization ${orgId}. Run: mastra auth orgs`);\n  }\n}\n","sourceCodeStart":359,"sourceCodeEnd":380,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/auth/credentials.ts#L359-L380","documentation":"validateOrgAccess fetches the orgs the current token can access and confirms the target orgId is among them. If not, it throws 'No access to organization <orgId>. Run: mastra auth orgs', telling the developer the credential belongs to a different account/org or the id is wrong. Called by deploys, logs, status, and suggestions commands before scoping to an org.","triggerScenarios":"deploysAction, logsAction, statusAction, or suggestionsAction passes an orgId (from flag/config/env) that is absent from fetchOrgs(token) results — org id typo'd, stale org from deleted/old account, or token from a different login without membership.","commonSituations":"Hard-coded MASTRA_ORG_ID from a previous employer/project; org deleted or renamed with a new id; multiple accounts — logged into personal account while targeting a work org id; copy-pasted org id with whitespace/case mismatch.","solutions":["Run `mastra auth orgs` to list orgs the current credentials can access and use one of those ids.","Switch accounts with `mastra auth login` using the account that belongs to the target org.","Correct the orgId in the config/env/flag where it is set.","Verify membership: if the org exists but is not listed, request access from the org admin."],"exampleFix":"// before\nMASTRA_ORG_ID=org_old123 mastra deploy\n// after\nmastra auth orgs            # list accessible orgs\nMASTRA_ORG_ID=org_live456 mastra deploy","handlingStrategy":"validation","validationCode":"const { fetchOrgs } = await import('./api.js');\nconst { getToken } = await import('./credentials.js');\nconst orgs = await fetchOrgs(await getToken(signal, { allowLogin: false }));\nif (!orgs.some(o => o.id === targetOrgId)) {\n  throw new Error(`Org ${targetOrgId} not accessible; run \\`mastra auth orgs\\` to list valid ids`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await validateOrgAccess(token, orgId);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('No access to organization')) {\n    console.error(`${err.message}\\nAccessible orgs:`);\n    (await fetchOrgs(token)).forEach(o => console.error(`  ${o.id} ${o.name}`));\n    return;\n  }\n  throw err;\n}","preventionTips":["Run `mastra auth orgs` to confirm org ids before hard-coding them in config/CI.","Remove stale MASTRA_ORG_ID values when switching accounts or employers.","Log into the account that actually holds membership in the target org.","Trim/normalize org ids read from env or config to avoid copy-paste whitespace mismatches."],"tags":["cli","auth","organization","permissions","rbac"],"backgroundTag":"org-access-denied","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}