Fix Cloudflare avatar upload

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 00:11:01 +00:00
parent 7b72a6a266
commit 8d5e235772
2 changed files with 31 additions and 5 deletions

View File

@@ -9,6 +9,15 @@ const corsHeaders = {
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID');
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
// Validate configuration at startup
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
console.error('[OAuth Profile] Missing Cloudflare configuration:', {
hasAccountId: !!CLOUDFLARE_ACCOUNT_ID,
hasApiToken: !!CLOUDFLARE_API_TOKEN,
});
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
}
interface GoogleUserMetadata {
email?: string;
name?: string;
@@ -106,8 +115,16 @@ Deno.serve(async (req) => {
// Download and upload avatar to Cloudflare
if (avatarUrl) {
try {
console.log('[OAuth Profile] Downloading avatar from:', avatarUrl);
// Validate secrets before attempting upload
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
console.warn('[OAuth Profile] Missing:', {
accountId: !CLOUDFLARE_ACCOUNT_ID,
apiToken: !CLOUDFLARE_API_TOKEN,
});
} else {
try {
console.log('[OAuth Profile] Downloading avatar from:', avatarUrl);
// Download image with timeout
const controller = new AbortController();
@@ -176,9 +193,15 @@ Deno.serve(async (req) => {
} else {
throw new Error('Cloudflare upload failed');
}
} catch (error) {
console.error('[OAuth Profile] Avatar upload failed:', error);
// Continue without avatar - don't block profile creation
} catch (error) {
console.error('[OAuth Profile] Avatar upload failed:', {
error: error.message,
accountId: CLOUDFLARE_ACCOUNT_ID,
hasToken: !!CLOUDFLARE_API_TOKEN,
avatarUrl,
});
// Continue without avatar - don't block profile creation
}
}
}