From d8ba1376291b22705e5b45c78228bf14abcc1960 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 04:24:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20createApiClient=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMailBusiness.tsx | 20 +++++++++++--------- src/api/hooks/Mail/useGetMailUniv.tsx | 20 +++++++++++--------- src/api/hooks/Mail/usePostMail.tsx | 18 +++++++++++------- 3 files changed, 33 insertions(+), 25 deletions(-) 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) {