Only add authorization header if token exists

This commit is contained in:
Erik Larsson
2021-01-30 04:03:43 +01:00
parent 5ba0804189
commit 320708e171
4 changed files with 24 additions and 19 deletions
@@ -39,12 +39,15 @@ export class KubernetesBackendClient implements KubernetesApi {
): Promise<any> {
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}${path}`;
const idToken = await this.identityApi.getIdToken();
const headers = {
'Content-Type': 'application/json',
} as { [header: string]: string };
if (idToken) {
headers.authorization = `Bearer ${idToken}`;
}
const response = await fetch(url, {
method: 'POST',
headers: {
authorization: `Bearer ${idToken}`,
'Content-Type': 'application/json',
},
headers,
body: JSON.stringify(requestBody),
});