Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 8427d31

Browse files
authored
Merge pull request #95 from djcruz93/fix-set-avatar-on-signup
[FIX] Set Github Avatar on Login, Remove rcPassword from rc4git_token
2 parents 8b435b4 + 83f6976 commit 8427d31

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

client/src/components/SignedLeftSidebar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export default function SignedLeftSidebar(props) {
209209
<img
210210
className="left-sidebar-user-avatar"
211211
alt={"username"}
212-
src={props.user.avatarUrl}
212+
src={`${rcApiDomain}/avatar/${props.user.username}`}
213213
onClick={handleProfileClick}
214214
></img>
215215
<Menu
@@ -233,7 +233,7 @@ export default function SignedLeftSidebar(props) {
233233
<img
234234
className="profile-menu-img"
235235
alt={"username"}
236-
src={props.user.avatarUrl}
236+
src={`${rcApiDomain}/avatar/${props.user.username}`}
237237
></img>
238238
</div>
239239
<div className="profile-right-container">

server/controllers/login.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ module.exports.createToken = async function (req, res) {
5454
},
5555
});
5656
newUser["name"] = ghUserResponse.data.name || ghUserResponse.data.login;
57-
newUser["username"] = `${ghUserResponse.data.login}_github`;
57+
newUser["username"] = `${ghUserResponse.data.login}`;
5858
newUser["avatarUrl"] = ghUserResponse.data.avatar_url;
59+
5960
/*
6061
In order to handle a case when user tries signing in gets created on RC but fails get stored in our db due to some error
6162
To keep it consistent with RC we store the (user-email,encrypted-rcPassword) pair in our fs so that it can be used
@@ -90,9 +91,9 @@ module.exports.createToken = async function (req, res) {
9091
},
9192
data: `{
9293
"name": "${newUser.name}",
93-
"email": "${newUser.username}@rc4git.com",
94+
"email": "${newUser.username}@rc4community.com",
9495
"pass": "${rcPassword}",
95-
"username": "${newUser.username}_rc4git"
96+
"username": "${newUser.username}"
9697
}`,
9798
});
9899
newUser["rcPassword"] = encryptedRCPassword;
@@ -124,20 +125,37 @@ module.exports.createToken = async function (req, res) {
124125
decipher.update(user.rcPassword, "hex", "utf8") +
125126
decipher.final("utf8")
126127
}",
127-
"user": "${user.username}_rc4git"
128+
"user": "${user.username}"
128129
}`,
129130
});
130131

132+
if (rcLoginUserResponse.data.data.me.avatarUrl !== user.avatarUrl) {
133+
await axios({
134+
method: "post",
135+
url: `${constants.rocketChatDomain}/api/v1/users.setAvatar`,
136+
headers: {
137+
"Content-type": "application/json",
138+
"X-Auth-Token": rcLoginUserResponse.data.data.authToken,
139+
"X-User-Id": rcLoginUserResponse.data.data.userId,
140+
},
141+
data: { avatarUrl: `${user.avatarUrl}` },
142+
});
143+
}
144+
145+
let userData = { ...user.toJSON() };
146+
delete userData["rcPassword"];
147+
131148
return res.status(200).json({
132149
success: true,
133150
data: {
134151
rc_token: rcLoginUserResponse.data.data.authToken,
135152
rc_uid: rcLoginUserResponse.data.data.userId,
136-
rc4git_token: jwt.sign(user.toJSON(), constants.jwtSecret),
153+
rc4git_token: jwt.sign(userData, constants.jwtSecret),
137154
gh_login_token: ghTokenResponse.data.access_token,
138155
},
139156
});
140157
} catch (err) {
158+
console.log(err);
141159
return res.status(500).json({
142160
success: false,
143161
error: `Internal Server Error ---> ${err}`,

0 commit comments

Comments
 (0)