Skip to content

Commit

Permalink
update profile picture (danny-avila#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
berry-13 authored Aug 17, 2023
1 parent afd43af commit 1dacfa4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions api/strategies/discordStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ const discordLogin = async () =>
const email = profile.email;
const discordId = profile.id;

const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
}

let avatarURL;
if (profile.avatar) {
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
Expand All @@ -31,6 +26,13 @@ const discordLogin = async () =>
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({
provider: 'discord',
discordId,
Expand Down
2 changes: 2 additions & 0 deletions api/strategies/githubStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const githubLogin = async () =>

const oldUser = await User.findOne({ email });
if (oldUser) {
oldUser.avatar = profile.photos[0].value;
await oldUser.save();
return cb(null, oldUser);
}

Expand Down
2 changes: 2 additions & 0 deletions api/strategies/googleStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const googleLogin = async () =>
try {
const oldUser = await User.findOne({ email: profile.emails[0].value });
if (oldUser) {
oldUser.avatar = profile.photos[0].value;
await oldUser.save();
return cb(null, oldUser);
}
} catch (err) {
Expand Down

0 comments on commit 1dacfa4

Please sign in to comment.