Skip to content

Commit

Permalink
fix(user-settings): use non-deprecated IdentityApi methods
Browse files Browse the repository at this point in the history
This fixes the undefined identity error that is being thrown on the user-settings page.

Signed-off-by: Reinoud Kruithof <2184455+reinoudk@users.noreply.github.com>
  • Loading branch information
reinoudk committed Dec 16, 2021
1 parent 22354ee commit 2a37405
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-suns-sit.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-user-settings': patch
---

Fix undefined identity bug in UserSettingsProfileCard caused by using deprecated methods of the IdentityApi
31 changes: 27 additions & 4 deletions plugins/user-settings/src/components/useUserProfileInfo.ts
Expand Up @@ -14,13 +14,36 @@
* limitations under the License.
*/

import { useApi, identityApiRef } from '@backstage/core-plugin-api';
import {
useApi,
identityApiRef,
BackstageUserIdentity,
ProfileInfo,
} from '@backstage/core-plugin-api';
import { useEffect, useState } from 'react';

export const useUserProfile = () => {
const identityApi = useApi(identityApiRef);
const userId = identityApi.getUserId();
const profile = identityApi.getProfile();
const displayName = profile.displayName ?? userId;

const [displayName, setDisplayName] = useState<
string | BackstageUserIdentity
>('');
const [profile, setProfile] = useState<ProfileInfo>({});

const getUserProfile = async () => {
const backstageIdentity = await identityApi.getBackstageIdentity();
const profileInfo = await identityApi.getProfileInfo();
const name = profileInfo.displayName ?? backstageIdentity;

setDisplayName(name);
setProfile(profileInfo);
};

useEffect(() => {
if (!displayName) {
getUserProfile();
}
});

return { profile, displayName };
};

0 comments on commit 2a37405

Please sign in to comment.