40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { createClient } from '@supabase/supabase-js';
|
|
import { Database } from '../types/supabase';
|
|
|
|
// Work around TypeScript errors with Vite environment variables
|
|
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL as string;
|
|
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY as string;
|
|
|
|
console.log('Initializing Supabase client...');
|
|
console.log('URL available:', !!supabaseUrl);
|
|
console.log('Key available:', !!supabaseAnonKey);
|
|
|
|
if (!supabaseUrl || !supabaseAnonKey) {
|
|
console.error('Missing Supabase environment variables!');
|
|
throw new Error('Missing Supabase environment variables');
|
|
}
|
|
|
|
// Create the Supabase client
|
|
const client = createClient<Database>(supabaseUrl, supabaseAnonKey, {
|
|
auth: {
|
|
autoRefreshToken: true,
|
|
persistSession: true,
|
|
}
|
|
});
|
|
|
|
// Test the connection
|
|
(async () => {
|
|
try {
|
|
const { data, error } = await client.from('species').select('id').limit(1);
|
|
if (error) {
|
|
console.error('Failed to connect to Supabase:', error.message);
|
|
} else {
|
|
console.log('Successfully connected to Supabase');
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to test Supabase connection:', e);
|
|
}
|
|
})();
|
|
|
|
// Export the client
|
|
export const supabase = client; |