diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 576695c0..7820b4a1 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -489,23 +489,17 @@ export const ModerationQueue = forwardRef((props, ref) => { try { console.log('Attempting to delete image from Cloudflare:', imageId); - // Direct fetch call to the edge function with proper DELETE method - const response = await fetch('https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image', { + // Use Supabase SDK - automatically includes session token + const { data, error } = await supabase.functions.invoke('upload-image', { method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4` - }, - body: JSON.stringify({ imageId }) + body: { imageId } }); - if (!response.ok) { - const errorData = await response.text(); - throw new Error(`HTTP ${response.status}: ${errorData}`); + if (error) { + throw new Error(`Failed to delete image: ${error.message}`); } - const result = await response.json(); - console.log('Successfully deleted image:', imageId, result); + console.log('Successfully deleted image:', imageId, data); } catch (deleteError) { console.error(`Failed to delete photo ${imageId} from Cloudflare:`, deleteError);