Mastra Supabase Auth integration
npm install @mastra/auth-supabaseA Supabase authentication integration for Mastra, providing seamless authentication and authorization capabilities using Supabase's authentication system.
- Node.js 22.13.0 or later
- Supabase project with authentication enabled
- Supabase URL and anonymous key
``bash`
npm install @mastra/auth-supabaseor
yarn add @mastra/auth-supabaseor
pnpm add @mastra/auth-supabase
`typescript
import { Mastra } from '@mastra/core/mastra';
import { MastraAuthSupabase } from '@mastra/auth-supabase';
// Initialize with environment variables
const supabaseAuth = new MastraAuthSupabase();
// Or initialize with explicit configuration
const supabaseAuth = new MastraAuthSupabase({
url: 'your-supabase-url',
anonKey: 'your-supabase-anon-key',
});
// Enable auth in Mastra
const mastra = new Mastra({
...
server: {
auth: supabaseAuth,
},
});
`
The package can be configured in two ways:
1. Environment Variables:
- SUPABASE_URL: Your Supabase project URLSUPABASE_ANON_KEY
- : Your Supabase anonymous key
2. Constructor Options:
`typescript``
interface MastraAuthSupabaseOptions {
url?: string;
anonKey?: string;
}
- Authentication: Verifies user tokens and retrieves user information from Supabase
- Authorization: Checks user permissions based on their role in Supabase
- Type Safety: Full TypeScript support with proper type definitions
- Environment Variable Support: Easy configuration through environment variables
Authenticates a user token and returns the user information if valid.
Checks if a user has the required permissions (currently checks for admin status).