Add support for Discord discriminators and email storage

This commit is contained in:
Eliot Partridge
2019-08-30 11:22:11 -05:00
parent 0ae32c4ad0
commit 88d14fe645
+7 -1
View File
@@ -21,7 +21,9 @@ export interface OAuthProfile {
id?: string; id?: string;
name?: OAuthProfileName; name?: OAuthProfileName;
username?: string; username?: string;
discriminator?: string; // discord
displayName?: string; displayName?: string;
email?: string; // discord
emails?: { value: string; }[]; emails?: { value: string; }[];
provider: string; provider: string;
gender?: string; gender?: string;
@@ -118,7 +120,9 @@ export function getProfileUrl(profile: OAuthProfile): string | undefined {
} }
export function getProfileEmails(profile: OAuthProfile): string[] { export function getProfileEmails(profile: OAuthProfile): string[] {
if (profile.emails && profile.emails.length) { if (profile.provider === 'discord') {
return [profile.email as string];
} else if (profile.emails && profile.emails.length) {
return profile.emails.map(e => e.value); return profile.emails.map(e => e.value);
} else if (profile._json && profile._json.attributes && profile._json.attributes.email) { // patreon } else if (profile._json && profile._json.attributes && profile._json.attributes.email) { // patreon
return [profile._json.attributes.email]; return [profile._json.attributes.email];
@@ -128,10 +132,12 @@ export function getProfileEmails(profile: OAuthProfile): string[] {
} }
export function getProfileUsername(profile: OAuthProfile): string | undefined { export function getProfileUsername(profile: OAuthProfile): string | undefined {
if (profile.provider === 'discord') return `${profile.username}#${profile.discriminator}`;
return profile.username || profile.displayName || getProfileNameInternal(profile.name); return profile.username || profile.displayName || getProfileNameInternal(profile.name);
} }
export function getProfileName(profile: OAuthProfile): string | undefined { export function getProfileName(profile: OAuthProfile): string | undefined {
if (profile.provider === 'discord') return `${profile.username}#${profile.discriminator}`;
return profile.displayName || profile.username || getProfileNameInternal(profile.name); return profile.displayName || profile.username || getProfileNameInternal(profile.name);
} }