Skip to content

Commit aaef91c

Browse files
authored
Merge pull request #27 from next-engineer/feature/24-id-token-add
✨ feat(api): id_token 헤더 포함
2 parents 6ebf6bf + bdf0a8f commit aaef91c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/api/axiosInstance.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function getAccessToken(): string | null {
2121
return tokens?.accessToken ?? localStorage.getItem('access_token');
2222
}
2323

24+
function getIdToken(): string | null {
25+
const { tokens } = useAuthStore.getState();
26+
return tokens?.idToken ?? localStorage.getItem('id_token');
27+
}
28+
2429
function toAbsoluteURL(url?: string, cfgBaseURL?: string): URL | null {
2530
if (!url) return null;
2631
try {
@@ -63,14 +68,8 @@ function safeRequestLog(config: InternalAxiosRequestConfig) {
6368
const headers = { ...(config.headers as Record<string, unknown>) };
6469
if ('Authorization' in headers) headers.Authorization = 'Bearer ***';
6570
if ('authorization' in headers) headers.authorization = 'Bearer ***';
66-
67-
console.log('API Request:', {
68-
method: config.method?.toUpperCase(),
69-
url: config.url,
70-
baseURL: config.baseURL,
71-
data: config.data,
72-
headers,
73-
});
71+
if ('X-ID-Token' in headers) headers['X-ID-Token'] = '***';
72+
if ('x-id-token' in headers) headers['x-id-token'] = '***';
7473
}
7574

7675
function safeResponseLog(res: AxiosResponse) {
@@ -101,6 +100,11 @@ api.interceptors.request.use((config) => {
101100
config.headers = config.headers ?? {};
102101
(config.headers as Record<string, string>).Authorization = `Bearer ${token}`;
103102
}
103+
const idToken = getIdToken();
104+
if (idToken) {
105+
config.headers = config.headers ?? {};
106+
(config.headers as Record<string, string>)['X-ID-Token'] = idToken;
107+
}
104108
}
105109
safeRequestLog(config);
106110
return config;
@@ -120,9 +124,6 @@ api.interceptors.response.use(
120124
localStorage.removeItem('access_token');
121125
localStorage.removeItem('id_token');
122126
localStorage.removeItem('refresh_token');
123-
124-
// 필요 시 로그인으로 이동 (리프레시 플로우 별도 이슈에서)
125-
// window.location.assign('/login');
126127
}
127128
safeErrorLog(err);
128129
return Promise.reject(err);

0 commit comments

Comments
 (0)