Force anon key on getHistory and expose errors visually

This commit is contained in:
Christian Vidal Wolf
2026-04-10 19:48:33 +02:00
parent 1c72eae60a
commit d3c90120f4
+25 -5
View File
@@ -133,16 +133,36 @@ export async function getHistory(token?: string): Promise<HistoryEntry[]> {
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'
}];
}
}