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 {
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);