Fix image deletion authentication

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 18:28:38 +00:00
parent 1b6da4fffa
commit be421658c1

View File

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