Commit 26df8898 authored by tom's avatar tom

Revert "remove Authorization header for API calls"

This reverts commit c98c7551.
parent 79217de9
......@@ -170,6 +170,7 @@ export interface ApiResource {
endpoint?: string;
basePath?: string;
pathParams?: Array<string>;
needAuth?: boolean; // for external APIs which require authentication
headers?: RequestInit['headers'];
}
......@@ -213,6 +214,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const, 'type' as const ],
endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint,
basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath,
needAuth: true,
},
verified_addresses: {
......@@ -220,6 +222,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const ],
endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint,
basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath,
needAuth: true,
},
token_info_applications_config: {
......@@ -227,6 +230,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const ],
endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint,
basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath,
needAuth: true,
},
token_info_applications: {
......@@ -234,6 +238,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const, 'id' as const ],
endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint,
basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath,
needAuth: true,
},
// AUTH
......
......@@ -8,6 +8,7 @@ import config from 'configs/app';
import isBodyAllowed from 'lib/api/isBodyAllowed';
import isNeedProxy from 'lib/api/isNeedProxy';
import { getResourceKey } from 'lib/api/useApiQuery';
import * as cookies from 'lib/cookies';
import type { Params as FetchParams } from 'lib/hooks/useFetch';
import useFetch from 'lib/hooks/useFetch';
......@@ -31,11 +32,14 @@ export default function useApiFetch() {
resourceName: R,
{ pathParams, queryParams, fetchParams, logError }: Params<R> = {},
) => {
const apiToken = cookies.get(cookies.NAMES.API_TOKEN);
const resource: ApiResource = RESOURCES[resourceName];
const url = buildUrl(resourceName, pathParams, queryParams);
const withBody = isBodyAllowed(fetchParams?.method);
const headers = pickBy({
'x-endpoint': resource.endpoint && isNeedProxy() ? resource.endpoint : undefined,
Authorization: resource.endpoint && resource.needAuth ? apiToken : undefined,
'x-csrf-token': withBody && csrfToken ? csrfToken : undefined,
...resource.headers,
...fetchParams?.headers,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment