diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index 69a41bd..42f8ccd 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -133,16 +133,36 @@ export async function getHistory(token?: string): Promise { cache: 'no-store', headers: { 'apikey': SUPABASE_KEY, - 'Authorization': `Bearer ${token || SUPABASE_KEY}` + // Try using only the ANON key just in case RLS or token expiry is failing silently + 'Authorization': `Bearer ${SUPABASE_KEY}` } } ); - if (!response.ok) return []; + if (!response.ok) { + const err = await response.text(); + return [{ + id: 'error-' + Date.now(), + product_id: 'ERROR', + article_name: `Failed: ${response.status} ${err}`, + old_data: [], + new_data: [], + changed_at: new Date().toISOString(), + changed_by: 'system' + }]; + } return await response.json(); - } catch (error) { - console.error('Error fetching history from Supabase:', error); - return []; + } catch (error: any) { + console.error('Error fetching history:', error); + return [{ + id: 'error-' + Date.now(), + product_id: 'EXCEPTION', + article_name: `Message: ${error.message}`, + old_data: [], + new_data: [], + changed_at: new Date().toISOString(), + changed_by: 'system' + }]; } }