Skip to content

Commit 71c2e44

Browse files
GMishxheliocastro
authored andcommitted
fix(gravatar): Fix the email for gravatar images
Signed-off-by: Gaurav Mishra <[email protected]>
1 parent b108fdd commit 71c2e44

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/app/[locale]/preferences/components/UserAccessToken.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ const UserAccessToken = (): ReactNode => {
3838
const { status } = useSession()
3939

4040
// Config values from backend
41-
const writeAuthorityAllowed =
42-
useConfigValue(UIConfigKeys.UI_REST_APITOKEN_WRITE_GENERATOR_ENABLE) === null
43-
? true
44-
: (useConfigValue(UIConfigKeys.UI_REST_APITOKEN_WRITE_GENERATOR_ENABLE) as boolean)
41+
const apiTokenGenerator = useConfigValue(UIConfigKeys.UI_REST_APITOKEN_WRITE_GENERATOR_ENABLE)
42+
const writeAuthorityAllowed = apiTokenGenerator === null ? true : (apiTokenGenerator as boolean)
4543

4644
useEffect(() => {
4745
if (status === 'unauthenticated') {

src/app/[locale]/preferences/components/UserInformation.tsx

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
// SPDX-License-Identifier: EPL-2.0
99
// License-Filename: LICENSE
1010

11-
import { useSession } from 'next-auth/react'
12-
import { useTranslations } from 'next-intl'
1311
import Link from 'next/link'
14-
15-
import { User } from '@/object-types'
12+
import { useTranslations } from 'next-intl'
1613
import { Gravatar } from 'next-sw360'
17-
1814
import { ReactNode } from 'react'
15+
import { User } from '@/object-types'
1916
import styles from '../preferences.module.css'
2017

2118
interface Props {
@@ -24,21 +21,6 @@ interface Props {
2421

2522
const UserInformation = ({ user }: Props): ReactNode => {
2623
const t = useTranslations('default')
27-
const { data: session } = useSession()
28-
let user_data: Record<string, string> | null = null
29-
30-
if (session) {
31-
try {
32-
const tokenPayloadBase64 = session.user.access_token.split('.')[1]
33-
const decodedPayload = Buffer.from(tokenPayloadBase64, 'base64').toString()
34-
user_data = JSON.parse(decodedPayload) as Record<string, string>
35-
} catch (error) {
36-
console.error('Failed to decode token payload:', error)
37-
user_data = null
38-
}
39-
}
40-
41-
const email_by_token: string = user_data ? user_data.user_name : '[email protected]'
4224

4325
return (
4426
<table className='table summary-table'>
@@ -87,11 +69,13 @@ const UserInformation = ({ user }: Props): ReactNode => {
8769
</ul>
8870
</td>
8971
</tr>
90-
<tr>
91-
<td colSpan={2}>
92-
<Gravatar email={email_by_token} />
93-
</td>
94-
</tr>
72+
{user && (
73+
<tr>
74+
<td colSpan={2}>
75+
<Gravatar email={user.email ? user.email : '[email protected]'} />
76+
</td>
77+
</tr>
78+
)}
9579
</tbody>
9680
</table>
9781
)

0 commit comments

Comments
 (0)