Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

MastraJwtAuth Class

The MastraJwtAuth class provides a lightweight authentication mechanism for Mastra using JSON Web Tokens (JWTs). It verifies incoming requests based on a shared secret and integrates with the Mastra server using the experimental_auth option.

Usage exampleDirect link to Usage example

src/mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { MastraJwtAuth } from "@mastra/auth";

export const mastra = new Mastra({
// ..
server: {
experimental_auth: new MastraJwtAuth({
secret: "<your-secret>",
}),
},
});

Constructor parametersDirect link to Constructor parameters

secret:

string
A unique string used to sign and verify JSON Web Tokens (JWTs) for authenticating incoming requests.

MastraJwtAuth

On this page