Skip to content

Commit

Permalink
hotfix: axios header
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhihi committed Jul 2, 2024
1 parent eb0a608 commit 5caae6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 70 deletions.
25 changes: 17 additions & 8 deletions src/api/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import { getToken } from '@components/login/AuthService';
const instance = axios.create({
baseURL: process.env.BASE_URL,
headers: { 'X-Custom-Header': 'foobar', 'Content-Type': 'application/json' },
timeout: 10000,
timeout: 1000,
});

instance.interceptors.request.use(
async (config) => {
console.log('Starting Request', JSON.stringify(config, null, 2));
if (config.url !== '/auth/google') {
const accessToken = await getToken();
if (accessToken) {
config.headers.Authorization = accessToken;
config.withCredentials = true;
}

if (config.url === '/auth/google') {
return config;
}

// 로그인 후 토큰 헤더에 추가
const accessToken = await getToken();
if (accessToken) {
config.headers.Authorization = `Bearer ${accessToken}`;
}
return config;
},
Expand All @@ -29,12 +32,18 @@ instance.interceptors.response.use(
console.log('Response:', JSON.stringify(response, null, 2));
return response;
},
(error) => {
async (error) => {
console.log('Error Response:', JSON.stringify(error, null, 2));

if (error.message === 'Network Error' && error.config) {
error.config.__isRetryRequest = true;
return axios(error.config);
}

if (error.response && error.response.status === 401 && error.config.url !== '/auth/google') {
console.log('토큰 만료');
// TODO: 토큰 재발급 로직 추가
}
return Promise.reject(error);
},
);
Expand Down
62 changes: 0 additions & 62 deletions src/api/axios.web.ts

This file was deleted.

0 comments on commit 5caae6d

Please sign in to comment.