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 auth option.
Usage exampleDirect link to Usage example
src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { MastraJwtAuth } from '@mastra/auth'
export const mastra = new Mastra({
server: {
auth: new MastraJwtAuth({
secret: '<your-secret>',
}),
},
})
Constructor parametersDirect link to Constructor parameters
secret?:
string
= process.env.JWT_AUTH_SECRET
A unique string used to sign and verify JSON Web Tokens (JWTs) for authenticating incoming requests. Falls back to
JWT_AUTH_SECRET when omitted. The resolved secret must be non-empty: the constructor throws an error if neither is set, or if this option is an empty string (an empty string does not fall back to JWT_AUTH_SECRET).