diff --git a/src/components/Profile/DisplayProfileImg.tsx b/src/components/Profile/DisplayProfileImg.tsx index bebfd4d53..36e80fef8 100644 --- a/src/components/Profile/DisplayProfileImg.tsx +++ b/src/components/Profile/DisplayProfileImg.tsx @@ -11,8 +11,11 @@ const DisplayProfileImg = () => { const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) const parsedUser = userProfile ? JSON.parse(userProfile) : null; - parsedUser.roles = orgRoles - setUserObj(parsedUser) + + if (parsedUser) { + parsedUser.roles = orgRoles; + setUserObj(parsedUser); + } } useEffect(() => { diff --git a/src/components/Profile/DisplayUser.tsx b/src/components/Profile/DisplayUser.tsx index 83a704006..fbc238f09 100644 --- a/src/components/Profile/DisplayUser.tsx +++ b/src/components/Profile/DisplayUser.tsx @@ -13,8 +13,11 @@ const DisplayUser = () => { const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) const parsedUser = userProfile ? JSON.parse(userProfile) : null - parsedUser.roles = orgRoles - setUserObj(parsedUser) + + if (parsedUser) { + parsedUser.roles = orgRoles; + setUserObj(parsedUser); + } } useEffect(() => { const fetchData = async () => { @@ -39,10 +42,10 @@ const DisplayUser = () => { className="text-xl font-medium text-gray-900 truncate dark:text-gray-300 mb-1" role="none" > - {userObj['firstName']} + {userObj?.['firstName']}
- {userObj['email']} + {userObj?.['email']}