import { SupabaseManagementClient } from './supabase-client'; /** * Simple authentication manager that delegates to Supabase client * No complex bridge patterns - just direct Supabase authentication */ export class AuthManager { private supabaseClient: SupabaseManagementClient; constructor() { this.supabaseClient = new SupabaseManagementClient(); } /** * Check if user is authenticated with Supabase */ async isAuthenticated(): Promise { return this.supabaseClient.isAuthenticated(); } /** * Authenticate with Supabase */ async authenticate(): Promise { return this.supabaseClient.authenticate(); } /** * Logout from Supabase */ async logout(): Promise { return this.supabaseClient.logout(); } /** * Get current user info (from Supabase) */ async getCurrentUser(): Promise { // For Supabase, we'll return basic info from the first organization const orgs = await this.supabaseClient.listOrganizations(); return { id: 'supabase-user', email: orgs[0]?.billing_email || 'unknown', organizations: orgs.length }; } /** * Make authenticated request - delegates to Supabase client */ async makeAuthenticatedRequest(endpoint: string, options: any = {}): Promise { // Map CLI endpoints to Supabase client methods if (endpoint === '/api/cli/supabase/organizations') { return this.supabaseClient.listOrganizations() as T; } if (endpoint === '/api/cli/supabase/projects' || endpoint.includes('/api/cli/supabase/projects?org=')) { const orgId = options.org || new URL(`http://dummy.com${endpoint}`).searchParams.get('org'); return this.supabaseClient.listProjects(orgId || undefined) as T; } if (endpoint === '/api/cli/supabase/provision') { return this.supabaseClient.createProject(options.data) as T; } if (endpoint.includes('/api/cli/supabase/projects/')) { const projectRef = endpoint.split('/').pop(); return this.supabaseClient.getProject(projectRef!) as T; } if (endpoint.includes('/api/cli/supabase/env/')) { const projectRef = endpoint.split('/').pop(); return this.supabaseClient.generateEnvVars(projectRef!) as T; } if (endpoint === '/api/cli/supabase/deploy-schema') { return this.supabaseClient.executeSQL(options.data.projectRef, options.data.schema) as T; } throw new Error(`Unsupported endpoint: ${endpoint}`); } }