Add auth header only when necessary
This commit is contained in:
@@ -235,7 +235,7 @@ export class GraphQLClient extends BaseClient<
|
|||||||
headers: {
|
headers: {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
...headers,
|
...headers,
|
||||||
Authorization: isAuthRequired && accessToken ? `Bearer ${accessToken}` : '',
|
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export class RestClient
|
|||||||
} = {},
|
} = {},
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
const updatedUrl = url.startsWith('http') ? url : `${this.getBaseUrl()}${url}`;
|
const updatedUrl = url.startsWith('http') ? url : `${this.getBaseUrl()}${url}`;
|
||||||
|
const isAuthRequired = AuthManager.isAuthRequired();
|
||||||
const accessToken = AuthManager.getAccessToken();
|
const accessToken = AuthManager.getAccessToken();
|
||||||
|
|
||||||
let result: Response;
|
let result: Response;
|
||||||
@@ -62,7 +63,7 @@ export class RestClient
|
|||||||
...config,
|
...config,
|
||||||
method: httpMethod,
|
method: httpMethod,
|
||||||
headers: {
|
headers: {
|
||||||
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
||||||
...this.config.headers,
|
...this.config.headers,
|
||||||
...config?.headers,
|
...config?.headers,
|
||||||
},
|
},
|
||||||
@@ -72,7 +73,7 @@ export class RestClient
|
|||||||
case HttpMethod.PATCH:
|
case HttpMethod.PATCH:
|
||||||
case HttpMethod.DELETE:
|
case HttpMethod.DELETE:
|
||||||
result = await this.client(updatedUrl, {
|
result = await this.client(updatedUrl, {
|
||||||
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
...(isAuthRequired && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
||||||
...this.config,
|
...this.config,
|
||||||
...config,
|
...config,
|
||||||
method: httpMethod,
|
method: httpMethod,
|
||||||
|
|||||||
Reference in New Issue
Block a user