mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:31:13 -05:00
Fix Discord OAuth data extraction
This commit is contained in:
@@ -31,8 +31,12 @@ interface DiscordUserMetadata {
|
|||||||
email?: string;
|
email?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
global_name?: string;
|
global_name?: string;
|
||||||
|
discriminator?: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
verified?: boolean;
|
||||||
|
flags?: number;
|
||||||
|
premium_type?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.serve(async (req) => {
|
Deno.serve(async (req) => {
|
||||||
@@ -75,12 +79,21 @@ Deno.serve(async (req) => {
|
|||||||
const discordIdentity = user.identities.find(i => i.provider === 'discord');
|
const discordIdentity = user.identities.find(i => i.provider === 'discord');
|
||||||
if (discordIdentity) {
|
if (discordIdentity) {
|
||||||
userMetadata = discordIdentity.identity_data || {};
|
userMetadata = discordIdentity.identity_data || {};
|
||||||
|
|
||||||
|
// Debug: Log full identity_data to see what Discord actually returns
|
||||||
|
console.log('[OAuth Profile] Discord identity_data (full):', JSON.stringify(discordIdentity.identity_data));
|
||||||
|
|
||||||
console.log('[OAuth Profile] Using Discord identity data:', {
|
console.log('[OAuth Profile] Using Discord identity data:', {
|
||||||
hasAvatar: !!userMetadata.avatar,
|
hasAvatar: !!userMetadata.avatar,
|
||||||
hasUsername: !!userMetadata.username,
|
hasUsername: !!userMetadata.username,
|
||||||
hasGlobalName: !!userMetadata.global_name,
|
hasGlobalName: !!userMetadata.global_name,
|
||||||
hasId: !!userMetadata.id
|
hasId: !!userMetadata.id,
|
||||||
|
hasEmail: !!userMetadata.email,
|
||||||
|
avatarValue: userMetadata.avatar,
|
||||||
|
idValue: userMetadata.id
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('[OAuth Profile] Discord provider found but no Discord identity in user.identities');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,18 +110,35 @@ Deno.serve(async (req) => {
|
|||||||
console.log('[OAuth Profile] Google user:', { avatarUrl, displayName, usernameBase });
|
console.log('[OAuth Profile] Google user:', { avatarUrl, displayName, usernameBase });
|
||||||
} else if (provider === 'discord') {
|
} else if (provider === 'discord') {
|
||||||
const discordData = userMetadata as DiscordUserMetadata;
|
const discordData = userMetadata as DiscordUserMetadata;
|
||||||
|
|
||||||
|
// Prefer global_name, fall back to username
|
||||||
displayName = discordData.global_name || discordData.username || null;
|
displayName = discordData.global_name || discordData.username || null;
|
||||||
usernameBase = discordData.username || null;
|
usernameBase = discordData.username || null;
|
||||||
|
|
||||||
// Extract email (Discord provides it)
|
// Extract email (Discord provides it with email scope)
|
||||||
const discordEmail = discordData.email || null;
|
const discordEmail = discordData.email || null;
|
||||||
|
|
||||||
|
// Validate we have minimum required data
|
||||||
|
if (!discordData.id) {
|
||||||
|
console.error('[OAuth Profile] Discord user ID missing - OAuth scopes may not be configured correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!discordData.username) {
|
||||||
|
console.warn('[OAuth Profile] Discord username missing - using ID as fallback');
|
||||||
|
usernameBase = discordData.id || null;
|
||||||
|
}
|
||||||
|
|
||||||
// Construct Discord avatar URL with proper format detection
|
// Construct Discord avatar URL with proper format detection
|
||||||
if (discordData.avatar && discordData.id) {
|
if (discordData.avatar && discordData.id) {
|
||||||
// Discord animated avatars have 'a_' prefix and use .gif extension
|
// Discord animated avatars have 'a_' prefix and use .gif extension
|
||||||
const isAnimated = discordData.avatar.startsWith('a_');
|
const isAnimated = discordData.avatar.startsWith('a_');
|
||||||
const extension = isAnimated ? 'gif' : 'png';
|
const extension = isAnimated ? 'gif' : 'png';
|
||||||
avatarUrl = `https://cdn.discordapp.com/avatars/${discordData.id}/${discordData.avatar}.${extension}?size=512`;
|
avatarUrl = `https://cdn.discordapp.com/avatars/${discordData.id}/${discordData.avatar}.${extension}?size=512`;
|
||||||
|
} else if (!discordData.avatar && discordData.id) {
|
||||||
|
// User has no custom avatar - use Discord default avatar
|
||||||
|
const defaultAvatarIndex = (parseInt(discordData.id) >> 22) % 6;
|
||||||
|
avatarUrl = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarIndex}.png`;
|
||||||
|
console.log('[OAuth Profile] Using Discord default avatar for user without custom avatar');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[OAuth Profile] Discord user:', {
|
console.log('[OAuth Profile] Discord user:', {
|
||||||
@@ -116,7 +146,8 @@ Deno.serve(async (req) => {
|
|||||||
displayName,
|
displayName,
|
||||||
usernameBase,
|
usernameBase,
|
||||||
email: discordEmail,
|
email: discordEmail,
|
||||||
hasAnimatedAvatar: discordData.avatar?.startsWith('a_')
|
hasAnimatedAvatar: discordData.avatar?.startsWith('a_'),
|
||||||
|
hasCustomAvatar: !!discordData.avatar
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('[OAuth Profile] Unsupported provider:', provider);
|
console.log('[OAuth Profile] Unsupported provider:', provider);
|
||||||
|
|||||||
Reference in New Issue
Block a user