plugins: migrate usage of deprecated IdentityApi methods

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-01-04 23:08:05 +01:00
parent 2916a83b9c
commit 51fbedc445
38 changed files with 221 additions and 195 deletions
@@ -96,7 +96,7 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
const baseUrl = `${await this.discoveryApi.getBaseUrl('azure-devops')}/`;
const url = new URL(path, baseUrl);
const idToken = await this.identityApi.getIdToken();
const { token: idToken } = await this.identityApi.getCredentials();
const response = await fetch(url.toString(), {
headers: idToken ? { Authorization: `Bearer ${idToken}` } : {},
});
@@ -15,8 +15,10 @@
*/
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
import useAsync from 'react-use/lib/useAsync';
export function useUserEmail(): string | undefined {
const identityApi = useApi(identityApiRef);
return identityApi.getProfile().email;
const state = useAsync(() => identityApi.getProfileInfo(), [identityApi]);
return state.value?.email;
}