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
- 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.
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
- 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.
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
- No organizations found. Create one at ${MASTRA_STUDIO_URL}
- No organization selected. Run: mastra auth orgs switch
- You have no organizations. Please create one at ${MASTRA_STU
- No organization matched --org "${value}". Available: ${avail
- Attaching a database requires the admin role in your organiz
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/35223c7c72a17c9d.
Report an issue: GitHub.