Skip to content

Commit 7205527

Browse files
committed
fix: 시험기간 조회 api 작동 오류 수정
1 parent 5096067 commit 7205527

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎src/lib/axios.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import axios from 'axios';
33
export const apiClient = axios.create({
44
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
55
// withCredentials: true, // 쿠키 사용하는 경우
6+
paramsSerializer: {
7+
serialize: (params) => {
8+
const searchParams = new URLSearchParams();
9+
Object.entries(params).forEach(([key, value]) => {
10+
if (Array.isArray(value)) {
11+
searchParams.append(key, value.join(','));
12+
} else if (value !== undefined && value !== null) {
13+
searchParams.append(key, String(value));
14+
}
15+
});
16+
return searchParams.toString();
17+
},
18+
},
619
});
720

821
// 요청 인터셉터: 토큰 삽입 등
@@ -17,12 +30,15 @@ apiClient.interceptors.request.use(
1730
(error) => Promise.reject(error),
1831
);
1932

20-
// 응답 인터셉터: 에러 로깅, 리프레시 처리 등
33+
// 응답 인터셉터: 401 시 로그인 페이지로 리다이렉트
2134
apiClient.interceptors.response.use(
2235
(response) => response,
2336
(error) => {
2437
if (error.response?.status === 401) {
25-
console.warn('인증 만료됨');
38+
localStorage.removeItem('token');
39+
if (typeof window !== 'undefined' && window.location.pathname !== '/login') {
40+
window.location.href = '/login';
41+
}
2642
}
2743
return Promise.reject(error);
2844
},

0 commit comments

Comments
 (0)