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.

MastraAuthClerk Class

The MastraAuthClerk class provides authentication for Mastra applications using Clerk. It verifies incoming requests with Clerk-issued JWT tokens 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 { MastraAuthClerk } from "@mastra/auth-clerk";

export const mastra = new Mastra({
// ..
server: {
experimental_auth: new MastraAuthClerk({
jwksUri: process.env.CLERK_JWKS_URI,
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
secretKey: process.env.CLERK_SECRET_KEY,
}),
},
});

Constructor parametersDirect link to Constructor parameters

publishableKey?:

string
= process.env.CLERK_PUBLISHABLE_KEY
Your Clerk publishable key. Can be found in your Clerk Dashboard under API Keys.

secretKey?:

string
= process.env.CLERK_SECRET_KEY
Your Clerk secret key. Used for server-side authentication and token verification.

jwksUri?:

string
= process.env.CLERK_JWKS_URI
The JWKS URI from your Clerk application. Used to verify JWT signatures.

name?:

string
Custom name for the auth provider instance.

authorizeUser?:

(user: User, request: HonoRequest) => Promise<boolean> | boolean
Custom authorization function to determine if a user should be granted access. Called after token verification. By default, allows all authenticated users.

MastraAuthClerk Class

On this page