nicholastay / passport-discord

Passport strategy for authentication with Discord (discordapp.com)
ISC License
172 stars 55 forks source link

profile.avatar is null for some users #48

Closed theoliberman closed 2 years ago

theoliberman commented 2 years ago

porile.avatar is null for some user with no apparent reason. They do not have the default discord's avatar and I can't see nothing in their settings that could prevent the API from getting this field. Do you think that this is coming from passport-discord library or could it be an issue of the discord's API itself. If someone knows about this problem and knows a way to get a user's avatar in an other way, i'll take it !

The code user :

passport.use(new DiscordStrategy({
    clientID: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    callbackURL: process.env.CLIENT_REDIRECT,
    scope: ["identify"]
}, async (accessToken, refreshToken, profile, done) => {
    console.log(profile)
    try {
        const user = await User.findOne(({ discordId: profile.id }))
        if (user) done(null, user)
        else {
            const newUser = await User.create({
                discordId: profile.id,
                username: profile.username,
                avatar: profile.avatar
            })
            const savedUser = await newUser.save()
            done(null, savedUser)
        }
    } catch (err) {
        done(err, null)
    }
}))

Thank you

theoliberman commented 2 years ago

Did some research and I have the same result with the Discord API. Closing this, sorry for the bother.