Skip to main content

Auth

Mastra lets you choose how you handle authentication, so you can secure access to your API and Studio using the identity system that fits your stack.

You can start with basic shared secret JWT authentication and switch to known providers when you need more advanced identity features.

What auth secures
Direct link to What auth secures

Configuring authentication locks down two things:

  • Studio UI: Studio displays a login screen (SSO, email/password, or both). When you also configure an RBAC provider, Studio enforces role-based access control to determine what each team member can see and do.
  • API routes: Built-in routes (/api/agents/*, /api/workflows/*, etc.) and custom routes require authentication, whether requests come from Studio or direct API calls. A few built-in routes stay public, such as GET /api/auth/capabilities, which Studio uses to detect the login state.

By default, the provider you set in server.auth protects both. To give Studio its own provider, also set studio.auth. Requests from Studio, including its calls to API routes, then use studio.auth exclusively. All other requests keep using server.auth.

A Studio login screen doesn't secure an otherwise public API. If you set only studio.auth, ordinary API requests remain unauthenticated. See Separate Studio and API authentication for the routing behavior and security implications.

Authentication is optional. If no auth is configured, all routes and Studio are publicly accessible. Public access can be enabled on individual custom routes using requiresAuth: false.

See Custom API Routes for controlling authentication on custom endpoints. Visit the Studio Auth docs for more on securing your Studio deployment.

warning

The default auth configuration protects /api/* and treats /api, /api/auth/* as public. When you set a custom server.apiPrefix, those defaults no longer match and built-in routes fall outside the protected pattern. Update server.auth.protected and server.auth.public to reference your new prefix.

note

Authentication for Studio is supported by Simple Auth, JWT, WorkOS, Better Auth, Google, and Clerk. Available login methods and required configuration depend on the provider. See the provider's guide for Studio single sign-on (SSO) setup, which can require credentials beyond those used for API token verification.

Available providers
Direct link to Available providers

Built-in
Direct link to Built-in

Third-party integrations
Direct link to Third-party integrations

Advanced
Direct link to Advanced

On this page