From 7e889bfb30c100a592623cea69d2f5a6869cd3d4 Mon Sep 17 00:00:00 2001 From: Reinoud Kruithof <2184455+reinoudk@users.noreply.github.com> Date: Fri, 17 Dec 2021 15:12:30 +0100 Subject: [PATCH] fix(user-settings): prevent using undefined value Signed-off-by: Reinoud Kruithof <2184455+reinoudk@users.noreply.github.com> --- .../src/components/useUserProfileInfo.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/user-settings/src/components/useUserProfileInfo.ts b/plugins/user-settings/src/components/useUserProfileInfo.ts index fbc7b92dcb..6f9b5c154e 100644 --- a/plugins/user-settings/src/components/useUserProfileInfo.ts +++ b/plugins/user-settings/src/components/useUserProfileInfo.ts @@ -17,6 +17,7 @@ import { alertApiRef, identityApiRef, + ProfileInfo, useApi, } from '@backstage/core-plugin-api'; import { useEffect } from 'react'; @@ -37,16 +38,22 @@ export const useUserProfile = () => { if (error) { alertApi.post({ message: `Failed to load user identity: ${error}`, - severity: "error", + severity: 'error', }); } }, [error, alertApi]); + if (loading || error) { + return { + profile: {} as ProfileInfo, + displayName: '', + loading, + }; + } + return { - profile: loading ? {} : value!.profile, - displayName: loading - ? '' - : value!.profile.displayName ?? value!.identity.userEntityRef, + profile: value!.profile, + displayName: value!.profile.displayName ?? value!.identity.userEntityRef, loading, }; };