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
+2 -4
View File
@@ -39,11 +39,9 @@ export class FossaClient implements FossaApi {
private async callApi(path: string): Promise<any> {
const apiUrl = `${await this.discoveryApi.getBaseUrl('proxy')}/fossa`;
const headers: Record<string, string> = {
authorization: await `Bearer ${this.identityApi.getIdToken()}`,
};
const idToken = await this.identityApi.getIdToken();
const response = await fetch(`${apiUrl}/${path}`, {
headers,
headers: idToken ? { authorization: `Bearer ${idToken}` } : {},
});
if (response.status === 200) {
return await response.json();