diff --git a/supabase/functions/process-oauth-profile/index.ts b/supabase/functions/process-oauth-profile/index.ts index 46c7c265..851c4239 100644 --- a/supabase/functions/process-oauth-profile/index.ts +++ b/supabase/functions/process-oauth-profile/index.ts @@ -86,11 +86,24 @@ Deno.serve(async (req) => { displayName = discordData.global_name || discordData.username || null; usernameBase = discordData.username || null; - // Construct Discord avatar URL + // Extract email (Discord provides it) + const discordEmail = discordData.email || null; + + // Construct Discord avatar URL with proper format detection if (discordData.avatar && discordData.id) { - avatarUrl = `https://cdn.discordapp.com/avatars/${discordData.id}/${discordData.avatar}.png?size=512`; + // Discord animated avatars have 'a_' prefix and use .gif extension + const isAnimated = discordData.avatar.startsWith('a_'); + const extension = isAnimated ? 'gif' : 'png'; + avatarUrl = `https://cdn.discordapp.com/avatars/${discordData.id}/${discordData.avatar}.${extension}?size=512`; } - console.log('[OAuth Profile] Discord user:', { avatarUrl, displayName, usernameBase }); + + console.log('[OAuth Profile] Discord user:', { + avatarUrl, + displayName, + usernameBase, + email: discordEmail, + hasAnimatedAvatar: discordData.avatar?.startsWith('a_') + }); } else { console.log('[OAuth Profile] Unsupported provider:', provider); return new Response(JSON.stringify({ success: true, message: 'Provider not supported' }), { @@ -199,6 +212,7 @@ Deno.serve(async (req) => { } catch (error) { console.error('[OAuth Profile] Avatar upload failed:', { error: error.message, + provider: provider, accountId: CLOUDFLARE_ACCOUNT_ID, accountHash: CLOUDFLARE_ACCOUNT_HASH, hasToken: !!CLOUDFLARE_API_TOKEN,