Add auth header only when necessary

This commit is contained in:
schroda
2025-08-27 00:22:17 +02:00
parent 592161353e
commit 0bd3370d89
2 changed files with 4 additions and 3 deletions

View File

@@ -235,7 +235,7 @@ export class GraphQLClient extends BaseClient<
headers: {
credentials: 'include',
...headers,
Authorization: isAuthRequired && accessToken ? `Bearer ${accessToken}` : '',
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
},
};
});

View File

@@ -51,6 +51,7 @@ export class RestClient
} = {},
): Promise<Response> => {
const updatedUrl = url.startsWith('http') ? url : `${this.getBaseUrl()}${url}`;
const isAuthRequired = AuthManager.isAuthRequired();
const accessToken = AuthManager.getAccessToken();
let result: Response;
@@ -62,7 +63,7 @@ export class RestClient
...config,
method: httpMethod,
headers: {
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
...this.config.headers,
...config?.headers,
},
@@ -72,7 +73,7 @@ export class RestClient
case HttpMethod.PATCH:
case HttpMethod.DELETE:
result = await this.client(updatedUrl, {
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
...this.config,
...config,
method: httpMethod,