update profile picture (#792)

This commit is contained in:
Marco Beretta 2023-08-17 20:32:31 +02:00 committed by GitHub
parent afd43afb60
commit 1dacfa49f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View file

@ -17,11 +17,6 @@ const discordLogin = async () =>
const email = profile.email; const email = profile.email;
const discordId = profile.id; const discordId = profile.id;
const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
}
let avatarURL; let avatarURL;
if (profile.avatar) { if (profile.avatar) {
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png'; const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
@ -31,6 +26,13 @@ const discordLogin = async () =>
avatarURL = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`; avatarURL = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`;
} }
const oldUser = await User.findOne({ email });
if (oldUser) {
oldUser.avatar = avatarURL;
await oldUser.save();
return cb(null, oldUser);
}
const newUser = await User.create({ const newUser = await User.create({
provider: 'discord', provider: 'discord',
discordId, discordId,

View file

@ -23,6 +23,8 @@ const githubLogin = async () =>
const oldUser = await User.findOne({ email }); const oldUser = await User.findOne({ email });
if (oldUser) { if (oldUser) {
oldUser.avatar = profile.photos[0].value;
await oldUser.save();
return cb(null, oldUser); return cb(null, oldUser);
} }

View file

@ -17,6 +17,8 @@ const googleLogin = async () =>
try { try {
const oldUser = await User.findOne({ email: profile.emails[0].value }); const oldUser = await User.findOne({ email: profile.emails[0].value });
if (oldUser) { if (oldUser) {
oldUser.avatar = profile.photos[0].value;
await oldUser.save();
return cb(null, oldUser); return cb(null, oldUser);
} }
} catch (err) { } catch (err) {