Add connection testing and fallback for Supabase
cgen-d3c88383855e49db8dd63e0d326a1cad
This commit is contained in:
parent
0711621b19
commit
478dc8836b
1 changed files with 31 additions and 14 deletions
|
|
@ -6,22 +6,39 @@ const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
|
|||
|
||||
// Validate required environment variables
|
||||
if (!supabaseUrl || !supabaseAnonKey) {
|
||||
throw new Error(
|
||||
"Missing Supabase environment variables. Please configure VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY",
|
||||
);
|
||||
console.error("Missing Supabase environment variables. Using demo mode.");
|
||||
// Use demo values for development
|
||||
const demoUrl = "https://demo.supabase.co";
|
||||
const demoKey = "demo-key";
|
||||
|
||||
export const isSupabaseConfigured = false;
|
||||
export const supabase = createClient<Database>(demoUrl, demoKey);
|
||||
} else {
|
||||
console.log("Supabase configured with URL:", supabaseUrl);
|
||||
export const isSupabaseConfigured = true;
|
||||
|
||||
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
|
||||
auth: {
|
||||
autoRefreshToken: true,
|
||||
persistSession: true,
|
||||
detectSessionInUrl: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Test the connection
|
||||
supabase.from('user_profiles').select('count', { count: 'exact', head: true })
|
||||
.then(({ error }) => {
|
||||
if (error) {
|
||||
console.error("Supabase connection test failed:", error);
|
||||
} else {
|
||||
console.log("Supabase connection test successful");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Supabase connection error:", err);
|
||||
});
|
||||
}
|
||||
|
||||
// Always true in production mode - Supabase is required
|
||||
export const isSupabaseConfigured = true;
|
||||
|
||||
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
|
||||
auth: {
|
||||
autoRefreshToken: true,
|
||||
persistSession: true,
|
||||
detectSessionInUrl: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Auth helpers
|
||||
export const auth = supabase.auth;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue