Skip to content

Commit 30ff9b1

Browse files
fix: show username on cert if name is private (freeCodeCamp#40897)
Co-authored-by: Shaun Hamilton <[email protected]>
1 parent ea1c132 commit 30ff9b1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

api-server/server/boot/certificate.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function createShowCert(app) {
423423
]
424424
});
425425
}
426-
const { isLocked, showCerts } = user.profileUI;
426+
const { isLocked, showCerts, showName } = user.profileUI;
427427

428428
if (!user.name) {
429429
return res.json({
@@ -512,6 +512,16 @@ function createShowCert(app) {
512512
}
513513

514514
const { username, name } = user;
515+
516+
if (!showName) {
517+
return res.json({
518+
certTitle,
519+
username,
520+
date: completedDate,
521+
completionTime
522+
});
523+
}
524+
515525
return res.json({
516526
certTitle,
517527
username,

client/src/client-only-routes/ShowCertification.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ const propTypes = {
7575
)
7676
})
7777
),
78+
profileUI: PropTypes.shape({
79+
showName: PropTypes.bool
80+
}),
7881
username: PropTypes.string
7982
}),
8083
userFetchState: PropTypes.shape({
@@ -230,13 +233,16 @@ const ShowCertification = props => {
230233

231234
const {
232235
date,
233-
name: userFullName,
236+
name: userFullName = null,
234237
username,
235238
certTitle,
236239
completionTime
237240
} = cert;
241+
238242
const { user } = props;
239243

244+
const displayName = userFullName ?? username;
245+
240246
const certDate = new Date(date);
241247
const certYear = certDate.getFullYear();
242248
const certMonth = certDate.getMonth();
@@ -328,7 +334,7 @@ const ShowCertification = props => {
328334
<div className='information-container'>
329335
<h3>This certifies that</h3>
330336
<h1>
331-
<strong>{userFullName}</strong>
337+
<strong>{displayName}</strong>
332338
</h1>
333339
<h3>has successfully completed the freeCodeCamp.org</h3>
334340
<h1>
@@ -362,7 +368,7 @@ const ShowCertification = props => {
362368
</Grid>
363369
{signedInUserName === username ? shareCertBtns : ''}
364370
<Spacer size={2} />
365-
<ShowProjectLinks user={user} name={userFullName} certName={certTitle} />
371+
<ShowProjectLinks user={user} name={displayName} certName={certTitle} />
366372
</div>
367373
);
368374
};

0 commit comments

Comments
 (0)