-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b3dfb0
commit 27247af
Showing
3 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import axios, { CreateAxiosDefaults } from "axios"; | ||
import { useUserInfo } from "@src/stores/useUserStore"; | ||
|
||
const baseConfig: CreateAxiosDefaults = { | ||
baseURL: `${import.meta.env.VITE_API_URL}`, | ||
withCredentials: true, | ||
}; | ||
|
||
export const unAuthorizationFetch = axios.create(baseConfig); | ||
|
||
export const fetch = axios.create(baseConfig); | ||
|
||
fetch.interceptors.request.use( | ||
function (config) { | ||
const { accessToken } = useUserInfo(); | ||
|
||
if (accessToken) { | ||
config.headers.Authorization = `Bearer ${accessToken}`; | ||
} | ||
|
||
return config; | ||
}, | ||
function (error) { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
// response 에러 처리 + access token 재발급 | ||
// fetch.interceptors.response.use( | ||
// function (response) { | ||
// return response; | ||
// }, | ||
// async function (error: AxiosError) { | ||
// const originalRequest: CustomAxiosRequestConfig | undefined = error.config; | ||
|
||
// if (error.response?.status === 401 && originalRequest && !originalRequest._retry) { | ||
// originalRequest._retry = true; | ||
// try { | ||
// const response = await getRefreshToken(); | ||
|
||
// const { payload } = response; | ||
|
||
// useUserStore.setState({ user: { accessToken: payload.accessToken } }); | ||
|
||
// originalRequest.headers.Authorization = `Bearer ${payload.accessToken}`; | ||
|
||
// return fetch(originalRequest); | ||
// } catch (error) { | ||
// if (error instanceof AxiosError && error.response?.status === 403) { | ||
// useUserStore.getState().removeCredentials(); | ||
// return; | ||
// } | ||
// } | ||
// } | ||
|
||
// return Promise.reject(error); | ||
// }, | ||
// ); | ||
``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters