Skip to content

Commit

Permalink
fix: ensure Images are produced for discord (nextauthjs#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnphpexpert committed Feb 1, 2021
1 parent 9833064 commit fe2ee0b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/providers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ export default (options) => {
scope: 'identify email',
params: { grant_type: 'authorization_code' },
accessTokenUrl: 'https://discord.com/api/oauth2/token',
authorizationUrl:
'https://discord.com/api/oauth2/authorize?response_type=code&prompt=none',
authorizationUrl: 'https://discord.com/api/oauth2/authorize?response_type=code&prompt=none',
profileUrl: 'https://discord.com/api/users/@me',
profile: (profile) => {
if (profile.avatar === null) {
const defaultAvatarNumber = parseInt(profile.discriminator) % 5
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`
} else {
const format = profile.premium_type === 1 || profile.premium_type === 2 ? 'gif' : 'png'
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`
}
return {
id: profile.id,
name: profile.username,
image: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`,
image: profile.image_url,
email: profile.email
}
},
Expand Down

0 comments on commit fe2ee0b

Please sign in to comment.