Skip to content

Commit 1dacfa4

Browse files
authored
update profile picture (danny-avila#792)
1 parent afd43af commit 1dacfa4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

api/strategies/discordStrategy.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ const discordLogin = async () =>
1717
const email = profile.email;
1818
const discordId = profile.id;
1919

20-
const oldUser = await User.findOne({ email });
21-
if (oldUser) {
22-
return cb(null, oldUser);
23-
}
24-
2520
let avatarURL;
2621
if (profile.avatar) {
2722
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
@@ -31,6 +26,13 @@ const discordLogin = async () =>
3126
avatarURL = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`;
3227
}
3328

29+
const oldUser = await User.findOne({ email });
30+
if (oldUser) {
31+
oldUser.avatar = avatarURL;
32+
await oldUser.save();
33+
return cb(null, oldUser);
34+
}
35+
3436
const newUser = await User.create({
3537
provider: 'discord',
3638
discordId,

api/strategies/githubStrategy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const githubLogin = async () =>
2323

2424
const oldUser = await User.findOne({ email });
2525
if (oldUser) {
26+
oldUser.avatar = profile.photos[0].value;
27+
await oldUser.save();
2628
return cb(null, oldUser);
2729
}
2830

api/strategies/googleStrategy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const googleLogin = async () =>
1717
try {
1818
const oldUser = await User.findOne({ email: profile.emails[0].value });
1919
if (oldUser) {
20+
oldUser.avatar = profile.photos[0].value;
21+
await oldUser.save();
2022
return cb(null, oldUser);
2123
}
2224
} catch (err) {

0 commit comments

Comments
 (0)