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 { ...@@ -170,6 +170,7 @@ export interface ApiResource {
endpoint?: string; endpoint?: string;
basePath?: string; basePath?: string;
pathParams?: Array<string>; pathParams?: Array<string>;
needAuth?: boolean; // for external APIs which require authentication
headers?: RequestInit['headers']; headers?: RequestInit['headers'];
} }
...@@ -213,6 +214,7 @@ export const RESOURCES = { ...@@ -213,6 +214,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const, 'type' as const ], pathParams: [ 'chainId' as const, 'type' as const ],
endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint, endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint,
basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath, basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath,
needAuth: true,
}, },
verified_addresses: { verified_addresses: {
...@@ -220,6 +222,7 @@ export const RESOURCES = { ...@@ -220,6 +222,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const ], pathParams: [ 'chainId' as const ],
endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint, endpoint: getFeaturePayload(config.features.verifiedTokens)?.api.endpoint,
basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath, basePath: getFeaturePayload(config.features.verifiedTokens)?.api.basePath,
needAuth: true,
}, },
token_info_applications_config: { token_info_applications_config: {
...@@ -227,6 +230,7 @@ export const RESOURCES = { ...@@ -227,6 +230,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const ], pathParams: [ 'chainId' as const ],
endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint, endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint,
basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath, basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath,
needAuth: true,
}, },
token_info_applications: { token_info_applications: {
...@@ -234,6 +238,7 @@ export const RESOURCES = { ...@@ -234,6 +238,7 @@ export const RESOURCES = {
pathParams: [ 'chainId' as const, 'id' as const ], pathParams: [ 'chainId' as const, 'id' as const ],
endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint, endpoint: getFeaturePayload(config.features.addressVerification)?.api.endpoint,
basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath, basePath: getFeaturePayload(config.features.addressVerification)?.api.basePath,
needAuth: true,
}, },
// AUTH // AUTH
......
...@@ -8,6 +8,7 @@ import config from 'configs/app'; ...@@ -8,6 +8,7 @@ import config from 'configs/app';
import isBodyAllowed from 'lib/api/isBodyAllowed'; import isBodyAllowed from 'lib/api/isBodyAllowed';
import isNeedProxy from 'lib/api/isNeedProxy'; import isNeedProxy from 'lib/api/isNeedProxy';
import { getResourceKey } from 'lib/api/useApiQuery'; import { getResourceKey } from 'lib/api/useApiQuery';
import * as cookies from 'lib/cookies';
import type { Params as FetchParams } from 'lib/hooks/useFetch'; import type { Params as FetchParams } from 'lib/hooks/useFetch';
import useFetch from 'lib/hooks/useFetch'; import useFetch from 'lib/hooks/useFetch';
...@@ -31,11 +32,14 @@ export default function useApiFetch() { ...@@ -31,11 +32,14 @@ export default function useApiFetch() {
resourceName: R, resourceName: R,
{ pathParams, queryParams, fetchParams, logError }: Params<R> = {}, { pathParams, queryParams, fetchParams, logError }: Params<R> = {},
) => { ) => {
const apiToken = cookies.get(cookies.NAMES.API_TOKEN);
const resource: ApiResource = RESOURCES[resourceName]; const resource: ApiResource = RESOURCES[resourceName];
const url = buildUrl(resourceName, pathParams, queryParams); const url = buildUrl(resourceName, pathParams, queryParams);
const withBody = isBodyAllowed(fetchParams?.method); const withBody = isBodyAllowed(fetchParams?.method);
const headers = pickBy({ const headers = pickBy({
'x-endpoint': resource.endpoint && isNeedProxy() ? resource.endpoint : undefined, 'x-endpoint': resource.endpoint && isNeedProxy() ? resource.endpoint : undefined,
Authorization: resource.endpoint && resource.needAuth ? apiToken : undefined,
'x-csrf-token': withBody && csrfToken ? csrfToken : undefined, 'x-csrf-token': withBody && csrfToken ? csrfToken : undefined,
...resource.headers, ...resource.headers,
...fetchParams?.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