mastra-ai/mastra · error · Error

No access to organization ${orgId}. Run: mastra auth orgs

Error message

No access to organization ${orgId}. Run: mastra auth orgs

What it means

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.

Source

Thrown at packages/cli/src/commands/auth/credentials.ts:377

  signal?.throwIfAborted();

  if (options.allowLogin === false || !isInteractive()) {
    throw new Error('Session expired. Run `mastra auth login` interactively or set MASTRA_API_TOKEN.');
  }
  const newCreds = await login(signal, options);
  return newCreds.token;
}

/**
 * Validate that the user has access to the specified organization.
 * Throws if the org is not in the user's org list.
 */
export async function validateOrgAccess(token: string, orgId: string): Promise<void> {
  const { fetchOrgs } = await import('./api.js');
  const orgs = await fetchOrgs(token);
  const hasAccess = orgs.some(o => o.id === orgId);
  if (!hasAccess) {
    throw new Error(`No access to organization ${orgId}. Run: mastra auth orgs`);
  }
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Run `mastra auth orgs` to list orgs the current credentials can access and use one of those ids.
  2. Switch accounts with `mastra auth login` using the account that belongs to the target org.
  3. Correct the orgId in the config/env/flag where it is set.
  4. Verify membership: if the org exists but is not listed, request access from the org admin.

Example fix

// before
MASTRA_ORG_ID=org_old123 mastra deploy
// after
mastra auth orgs            # list accessible orgs
MASTRA_ORG_ID=org_live456 mastra deploy
Defensive patterns

Strategy: validation

Validate before calling

const { fetchOrgs } = await import('./api.js');
const { getToken } = await import('./credentials.js');
const orgs = await fetchOrgs(await getToken(signal, { allowLogin: false }));
if (!orgs.some(o => o.id === targetOrgId)) {
  throw new Error(`Org ${targetOrgId} not accessible; run \`mastra auth orgs\` to list valid ids`);
}

Try / catch

try {
  await validateOrgAccess(token, orgId);
} catch (err) {
  if (err instanceof Error && err.message.startsWith('No access to organization')) {
    console.error(`${err.message}\nAccessible orgs:`);
    (await fetchOrgs(token)).forEach(o => console.error(`  ${o.id} ${o.name}`));
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/35223c7c72a17c9d. Report an issue: GitHub.