fix(user-settings): prevent using undefined value

Signed-off-by: Reinoud Kruithof <2184455+reinoudk@users.noreply.github.com>
This commit is contained in:
Reinoud Kruithof
2021-12-17 15:12:30 +01:00
parent 375ed38b16
commit 7e889bfb30
@@ -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,
};
};