@mastra/auth-supabase
A Supabase authentication integration for Mastra, providing seamless authentication and authorization capabilities using Supabase's authentication system.
Installation
npm install @mastra/auth-supabase
yarn add @mastra/auth-supabase
pnpm add @mastra/auth-supabase
Usage
import { Mastra } from '@mastra/core';
import { MastraAuthSupabase } from '@mastra/auth-supabase';
const auth = new MastraAuthSupabase();
const auth = new MastraAuthSupabase({
url: 'your-supabase-url',
anonKey: 'your-supabase-anon-key',
});
const mastra = new Mastra({
...
server: {
experimental_auth: auth,
},
});
Configuration
The package can be configured in two ways:
Features
- 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
API
authenticateToken(token: string)
Authenticates a user token and returns the user information if valid.
authorizeUser(user: User)
Checks if a user has the required permissions (currently checks for admin status).
Requirements
- Node.js 16 or higher
- Supabase project with authentication enabled
- Supabase URL and anonymous key
License
Elastic-2.0