Mastra Clerk Auth integration
npm install @mastra/auth-clerkA Mastra authentication provider for Clerk, enabling seamless integration of Clerk authentication with Mastra applications.
``bash`
npm install @mastra/auth-clerkor
yarn add @mastra/auth-clerkor
pnpm add @mastra/auth-clerk
`typescript
import { Mastra } from '@mastra/core/mastra';
import { MastraAuthClerk } from '@mastra/auth-clerk';
// Initialize the Clerk auth provider
const clerkAuth = new MastraAuthClerk({
jwksUri: 'your-jwks-uri',
secretKey: 'your-secret-key',
publishableKey: 'your-publishable-key',
});
// Or use environment variables
const clerkAuth = new MastraAuthClerk();
// Enable auth in Mastra
const mastra = new Mastra({
...
server: {
auth: clerkAuth,
},
});
`
The package can be configured either through constructor options or environment variables:
- CLERK_JWKS_URI: The JWKS URI for your Clerk instanceCLERK_SECRET_KEY
- : Your Clerk secret keyCLERK_PUBLISHABLE_KEY
- : Your Clerk publishable key
`typescript``
interface MastraAuthClerkOptions {
jwksUri?: string;
secretKey?: string;
publishableKey?: string;
}
- JWT token verification using Clerk's JWKS
- User authentication and authorization
- Organization membership verification
- Seamless integration with Mastra's authentication system
Verifies a JWT token and returns the associated user if valid.
Checks if a user is authorized by verifying their organization membership.