debug: add detailed error logging for trainers fetch
- Add console logs to debug Supabase connection - Improve error message handling for non-Error objects - Add client-side logging for Supabase configuration
This commit is contained in:
@@ -23,12 +23,26 @@ export default function TrainersPage() {
|
||||
const fetchTrainers = async () => {
|
||||
try {
|
||||
setError(null);
|
||||
console.log("Fetching trainers...");
|
||||
|
||||
const { data, error } = await supabase.from("trainers").select("*").order("name");
|
||||
if (error) throw error;
|
||||
|
||||
console.log("Supabase response:", { data, error });
|
||||
|
||||
if (error) {
|
||||
console.error("Supabase error:", error);
|
||||
throw new Error(error.message || "Database error");
|
||||
}
|
||||
|
||||
setTrainers(data || []);
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch trainers:", err);
|
||||
setError(err instanceof Error ? err.message : "Failed to connect to database");
|
||||
const errorMessage = err instanceof Error
|
||||
? err.message
|
||||
: typeof err === 'object' && err !== null
|
||||
? JSON.stringify(err)
|
||||
: "Failed to connect to database";
|
||||
setError(errorMessage);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL === 'your_supabase_project_url'
|
||||
? 'http://localhost:54321'
|
||||
: (process.env.NEXT_PUBLIC_SUPABASE_URL || 'http://localhost:54321')
|
||||
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY === 'your_supabase_anon_key'
|
||||
? 'placeholder-key'
|
||||
: (process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'placeholder-key')
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'http://localhost:54321'
|
||||
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
|
||||
|
||||
export const supabase = createClient(supabaseUrl, supabaseKey)
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log('Supabase URL:', supabaseUrl)
|
||||
console.log('Supabase Key configured:', !!supabaseKey)
|
||||
}
|
||||
|
||||
export const supabase = createClient(supabaseUrl, supabaseKey, {
|
||||
auth: {
|
||||
autoRefreshToken: true,
|
||||
persistSession: true,
|
||||
},
|
||||
})
|
||||
|
||||
export const isSupabaseConfigured = () => {
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL
|
||||
|
||||
Reference in New Issue
Block a user