diff --git a/src/api/hooks/Mail/useGetMailBusiness.tsx b/src/api/hooks/Mail/useGetMailBusiness.tsx index 38f2a41..abf32af 100644 --- a/src/api/hooks/Mail/useGetMailBusiness.tsx +++ b/src/api/hooks/Mail/useGetMailBusiness.tsx @@ -6,18 +6,20 @@ import { useQuery } from '@tanstack/react-query'; export const getMailPath = (page: number, size: number) => `${BASE_URL}/emails?page=${page}&size=${size}`; -const token = sessionStorage.getItem('accessToken'); - -const apiClient = axios.create({ - baseURL: BASE_URL, - headers: { - Authorization: `Bearer ${token}`, - Job: `business`, - }, -}); +const createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + Job: 'business', + }, + }); +}; const getMailBusiness = async (page: number, size: number) => { try { + const apiClient = createApiClient(); const response = await apiClient.get(getMailPath(page, size)); return response.data; } catch (error) { diff --git a/src/api/hooks/Mail/useGetMailUniv.tsx b/src/api/hooks/Mail/useGetMailUniv.tsx index 79e5e7d..939296d 100644 --- a/src/api/hooks/Mail/useGetMailUniv.tsx +++ b/src/api/hooks/Mail/useGetMailUniv.tsx @@ -6,18 +6,20 @@ import { useQuery } from '@tanstack/react-query'; export const getMailPath = (page: number, size: number) => `${BASE_URL}/emails?page=${page}&size=${size}`; -const token = sessionStorage.getItem('accessToken'); - -const apiClient = axios.create({ - baseURL: BASE_URL, - headers: { - Authorization: `Bearer ${token}`, - Job: `univ`, - }, -}); +const createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + Job: 'univ', + }, + }); +}; const getMailUniv = async (page: number, size: number) => { try { + const apiClient = createApiClient(); const response = await apiClient.get(getMailPath(page, size)); return response.data; } catch (error) { diff --git a/src/api/hooks/Mail/usePostMail.tsx b/src/api/hooks/Mail/usePostMail.tsx index ac86a5d..c76d829 100644 --- a/src/api/hooks/Mail/usePostMail.tsx +++ b/src/api/hooks/Mail/usePostMail.tsx @@ -4,17 +4,21 @@ import { BASE_URL } from '../..'; import { useMutation } from '@tanstack/react-query'; export const postMailPath = () => `${BASE_URL}/save-email`; -const token = sessionStorage.getItem('accessToken'); -const apiClient = axios.create({ - baseURL: BASE_URL, - headers: { - Authorization: `Bearer ${token}`, - }, -}); +const createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + }, + }); +}; const postMail = async (mailInput: MailPostData) => { try { + const apiClient = createApiClient(); const response = await apiClient.post(postMailPath(), mailInput); return response.data; } catch (error) {