mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add prefix to API resources * fix pw tests * refactor config * remove unnecessary prefixes in resource names * fixes * update screenshots
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import buildUrl from 'lib/api/buildUrl';
|
|
import isNeedProxy from 'lib/api/isNeedProxy';
|
|
import { getResourceKey } from 'lib/api/useApiQuery';
|
|
import * as cookies from 'lib/cookies';
|
|
import useFetch from 'lib/hooks/useFetch';
|
|
|
|
export default function useGetCsrfToken() {
|
|
const nodeApiFetch = useFetch();
|
|
|
|
return useQuery({
|
|
queryKey: getResourceKey('general:csrf'),
|
|
queryFn: async() => {
|
|
if (!isNeedProxy()) {
|
|
const url = buildUrl('general:csrf');
|
|
const apiResponse = await fetch(url, { credentials: 'include' });
|
|
const csrfFromHeader = apiResponse.headers.get('x-bs-account-csrf');
|
|
|
|
if (!csrfFromHeader) {
|
|
// I am not sure should we log this error or not
|
|
// so I commented it out for now
|
|
// rollbar?.warn('Client fetch failed', {
|
|
// resource: 'csrf',
|
|
// status_code: 500,
|
|
// status_text: 'Unable to obtain csrf token from header',
|
|
// });
|
|
return;
|
|
}
|
|
|
|
return { token: csrfFromHeader };
|
|
}
|
|
|
|
return nodeApiFetch('/node-api/csrf');
|
|
},
|
|
enabled: Boolean(cookies.get(cookies.NAMES.API_TOKEN)),
|
|
});
|
|
}
|