Fix Supabase configuration with fallback for missing environment variables
cgen-29fa12290ad14af2ac17820babaf345e
This commit is contained in:
parent
07d0b69cac
commit
0fafedb725
1 changed files with 18 additions and 9 deletions
|
|
@ -4,17 +4,26 @@ import type { Database } from './database.types';
|
|||
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
|
||||
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
|
||||
|
||||
if (!supabaseUrl || !supabaseAnonKey) {
|
||||
throw new Error('Missing Supabase environment variables');
|
||||
}
|
||||
// Check if Supabase is configured
|
||||
export const isSupabaseConfigured = !!(supabaseUrl && supabaseAnonKey &&
|
||||
supabaseUrl !== 'https://your-project-ref.supabase.co' &&
|
||||
supabaseAnonKey !== 'your-anon-key-here');
|
||||
|
||||
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
|
||||
auth: {
|
||||
autoRefreshToken: true,
|
||||
persistSession: true,
|
||||
detectSessionInUrl: true
|
||||
// Use fallback values for development if not configured
|
||||
const fallbackUrl = 'https://demo.supabase.co';
|
||||
const fallbackKey = 'demo-key';
|
||||
|
||||
export const supabase = createClient<Database>(
|
||||
supabaseUrl || fallbackUrl,
|
||||
supabaseAnonKey || fallbackKey,
|
||||
{
|
||||
auth: {
|
||||
autoRefreshToken: isSupabaseConfigured,
|
||||
persistSession: isSupabaseConfigured,
|
||||
detectSessionInUrl: isSupabaseConfigured
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
// Auth helpers
|
||||
export const auth = supabase.auth;
|
||||
|
|
|
|||
Loading…
Reference in a new issue