diff --git a/src/lib/requests/client/GraphQLClient.ts b/src/lib/requests/client/GraphQLClient.ts index f0f75b5d..54ae5ac6 100644 --- a/src/lib/requests/client/GraphQLClient.ts +++ b/src/lib/requests/client/GraphQLClient.ts @@ -235,7 +235,7 @@ export class GraphQLClient extends BaseClient< headers: { credentials: 'include', ...headers, - Authorization: isAuthRequired && accessToken ? `Bearer ${accessToken}` : '', + ...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), }, }; }); diff --git a/src/lib/requests/client/RestClient.ts b/src/lib/requests/client/RestClient.ts index 12ba04bd..ebc1e7c3 100644 --- a/src/lib/requests/client/RestClient.ts +++ b/src/lib/requests/client/RestClient.ts @@ -51,6 +51,7 @@ export class RestClient } = {}, ): Promise => { 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,