From 5fb92f97bd687e486c6d03b2ff0b533bddcd9749 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:29:25 +0000 Subject: [PATCH] Fix Discord OAuth profile handling --- .../functions/process-oauth-profile/index.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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,