From 88d14fe64567c69001893c40fc3e2d800b5d3b55 Mon Sep 17 00:00:00 2001 From: Eliot Partridge Date: Fri, 30 Aug 2019 11:22:11 -0500 Subject: [PATCH] Add support for Discord discriminators and email storage --- src/ts/server/oauth.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ts/server/oauth.ts b/src/ts/server/oauth.ts index dbc87ad..e2a4c80 100644 --- a/src/ts/server/oauth.ts +++ b/src/ts/server/oauth.ts @@ -21,7 +21,9 @@ export interface OAuthProfile { id?: string; name?: OAuthProfileName; username?: string; + discriminator?: string; // discord displayName?: string; + email?: string; // discord emails?: { value: string; }[]; provider: string; gender?: string; @@ -118,7 +120,9 @@ export function getProfileUrl(profile: OAuthProfile): string | undefined { } 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); } else if (profile._json && profile._json.attributes && profile._json.attributes.email) { // patreon return [profile._json.attributes.email]; @@ -128,10 +132,12 @@ export function getProfileEmails(profile: OAuthProfile): string[] { } export function getProfileUsername(profile: OAuthProfile): string | undefined { + if (profile.provider === 'discord') return `${profile.username}#${profile.discriminator}`; return profile.username || profile.displayName || getProfileNameInternal(profile.name); } export function getProfileName(profile: OAuthProfile): string | undefined { + if (profile.provider === 'discord') return `${profile.username}#${profile.discriminator}`; return profile.displayName || profile.username || getProfileNameInternal(profile.name); }