auth/supabase/README.md
A Supabase authentication integration for Mastra, providing seamless authentication and authorization capabilities using Supabase's authentication system.
npm install @mastra/auth-supabase
# or
yarn add @mastra/auth-supabase
# or
pnpm add @mastra/auth-supabase
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:
Environment Variables:
SUPABASE_URL: Your Supabase project URLSUPABASE_ANON_KEY: Your Supabase anonymous keyConstructor Options:
interface MastraAuthSupabaseOptions {
url?: string;
anonKey?: string;
}
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).