2022-02-23 08:52:31 +01:00
|
|
|
import { useRouter } from 'next/router';
|
2022-12-29 00:43:22 +01:00
|
|
|
import * as reactQuery from '@tanstack/react-query';
|
2023-03-03 21:37:26 +01:00
|
|
|
import { useApi as nextUseApi } from 'next-basics';
|
|
|
|
import { getClientAuthToken } from 'lib/client';
|
|
|
|
import { SHARE_TOKEN_HEADER } from 'lib/constants';
|
|
|
|
import useStore from 'store/app';
|
|
|
|
|
|
|
|
const selector = state => state.shareToken;
|
2022-02-27 00:53:45 +01:00
|
|
|
|
2022-12-29 00:43:22 +01:00
|
|
|
export default function useApi() {
|
2022-02-23 08:52:31 +01:00
|
|
|
const { basePath } = useRouter();
|
2023-03-03 21:37:26 +01:00
|
|
|
const shareToken = useStore(selector);
|
2022-02-23 08:52:31 +01:00
|
|
|
|
2023-03-03 21:37:26 +01:00
|
|
|
const { get, post, put, del } = nextUseApi(
|
|
|
|
{ authorization: `Bearer ${getClientAuthToken()}`, [SHARE_TOKEN_HEADER]: shareToken?.token },
|
|
|
|
basePath,
|
|
|
|
);
|
2022-02-23 08:52:31 +01:00
|
|
|
|
2022-12-29 00:43:22 +01:00
|
|
|
return { get, post, put, del, ...reactQuery };
|
2022-02-23 08:52:31 +01:00
|
|
|
}
|