From 5f8cb16453e9bf01305be1d5455efbe8bee5d8a0 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 12 Oct 2025 00:19:04 +0000 Subject: [PATCH] Fix: Use account hash for Cloudflare avatars --- .../functions/process-oauth-profile/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/supabase/functions/process-oauth-profile/index.ts b/supabase/functions/process-oauth-profile/index.ts index 0933ffef..c05b5c6b 100644 --- a/supabase/functions/process-oauth-profile/index.ts +++ b/supabase/functions/process-oauth-profile/index.ts @@ -6,16 +6,16 @@ const corsHeaders = { 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type', }; -const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID'); +const CLOUDFLARE_ACCOUNT_HASH = Deno.env.get('CLOUDFLARE_ACCOUNT_HASH'); const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN'); // Validate configuration at startup -if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) { +if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) { console.error('[OAuth Profile] Missing Cloudflare configuration:', { - hasAccountId: !!CLOUDFLARE_ACCOUNT_ID, + hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH, hasApiToken: !!CLOUDFLARE_API_TOKEN, }); - console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets'); + console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_HASH and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets'); } interface GoogleUserMetadata { @@ -116,10 +116,10 @@ Deno.serve(async (req) => { // Download and upload avatar to Cloudflare if (avatarUrl) { // Validate secrets before attempting upload - if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) { + if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) { console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload'); console.warn('[OAuth Profile] Missing:', { - accountId: !CLOUDFLARE_ACCOUNT_ID, + accountHash: !CLOUDFLARE_ACCOUNT_HASH, apiToken: !CLOUDFLARE_API_TOKEN, }); } else { @@ -153,7 +153,7 @@ Deno.serve(async (req) => { // Get upload URL from Cloudflare const uploadUrlResponse = await fetch( - `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload`, + `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_HASH}/images/v2/direct_upload`, { method: 'POST', headers: { @@ -188,7 +188,7 @@ Deno.serve(async (req) => { if (result.success) { cloudflareImageId = result.result.id; - cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_ID}/${cloudflareImageId}/avatar`; + cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${cloudflareImageId}/avatar`; console.log('[OAuth Profile] Uploaded to Cloudflare:', { cloudflareImageId, cloudflareImageUrl }); } else { throw new Error('Cloudflare upload failed'); @@ -196,7 +196,7 @@ Deno.serve(async (req) => { } catch (error) { console.error('[OAuth Profile] Avatar upload failed:', { error: error.message, - accountId: CLOUDFLARE_ACCOUNT_ID, + accountHash: CLOUDFLARE_ACCOUNT_HASH, hasToken: !!CLOUDFLARE_API_TOKEN, avatarUrl, });