Fix: Use correct Cloudflare credentials

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 00:24:58 +00:00
parent 5f8cb16453
commit 3d91092953

View File

@@ -6,16 +6,18 @@ const corsHeaders = {
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type', '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_ACCOUNT_HASH = Deno.env.get('CLOUDFLARE_ACCOUNT_HASH');
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN'); const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
// Validate configuration at startup // Validate configuration at startup
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) { if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
console.error('[OAuth Profile] Missing Cloudflare configuration:', { console.error('[OAuth Profile] Missing Cloudflare configuration:', {
hasAccountId: !!CLOUDFLARE_ACCOUNT_ID,
hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH, hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH,
hasApiToken: !!CLOUDFLARE_API_TOKEN, hasApiToken: !!CLOUDFLARE_API_TOKEN,
}); });
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_HASH and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets'); console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_ACCOUNT_HASH, and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
} }
interface GoogleUserMetadata { interface GoogleUserMetadata {
@@ -116,9 +118,10 @@ Deno.serve(async (req) => {
// Download and upload avatar to Cloudflare // Download and upload avatar to Cloudflare
if (avatarUrl) { if (avatarUrl) {
// Validate secrets before attempting upload // Validate secrets before attempting upload
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) { if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload'); console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
console.warn('[OAuth Profile] Missing:', { console.warn('[OAuth Profile] Missing:', {
accountId: !CLOUDFLARE_ACCOUNT_ID,
accountHash: !CLOUDFLARE_ACCOUNT_HASH, accountHash: !CLOUDFLARE_ACCOUNT_HASH,
apiToken: !CLOUDFLARE_API_TOKEN, apiToken: !CLOUDFLARE_API_TOKEN,
}); });
@@ -153,7 +156,7 @@ Deno.serve(async (req) => {
// Get upload URL from Cloudflare // Get upload URL from Cloudflare
const uploadUrlResponse = await fetch( const uploadUrlResponse = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_HASH}/images/v2/direct_upload`, `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload`,
{ {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -196,6 +199,7 @@ Deno.serve(async (req) => {
} catch (error) { } catch (error) {
console.error('[OAuth Profile] Avatar upload failed:', { console.error('[OAuth Profile] Avatar upload failed:', {
error: error.message, error: error.message,
accountId: CLOUDFLARE_ACCOUNT_ID,
accountHash: CLOUDFLARE_ACCOUNT_HASH, accountHash: CLOUDFLARE_ACCOUNT_HASH,
hasToken: !!CLOUDFLARE_API_TOKEN, hasToken: !!CLOUDFLARE_API_TOKEN,
avatarUrl, avatarUrl,