Skip to content

Commit

Permalink
feat: axios interceptor에서 토큰이 쿠키에 저장되어 있다면 가져오도록 설정 #179
Browse files Browse the repository at this point in the history
  • Loading branch information
seoye0ng committed Feb 20, 2024
1 parent fe575c1 commit 8f45e5b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/remote/api/common.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable no-param-reassign */
import { useCookies } from 'react-cookie';

import axios, { InternalAxiosRequestConfig, AxiosError, AxiosResponse } from 'axios';

import { axiosInstance } from '@remote/api/instance.api';
Expand All @@ -10,13 +12,14 @@ axiosInstance.interceptors.request.use(
* request 직전 공통으로 진행할 작업
*/
if (config && config.headers) {
// TODO: 인증할 때 받은 토큰을 쿠키에 저장했다면 가져옵니다.
// 인증할 때 받은 토큰을 쿠키에 저장했다면 가져옵니다.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [cookies, setCookie] = useCookies(['token']);

// const token = getCookie('token');
// if (token) {
// config.headers.Authorization = `Bearer ${token}`;
// config.headers['Content-Type'] = 'application/json';
// }
if (cookies.token) {
config.headers.Authorization = `Bearer ${cookies.token}`;
config.headers['Content-Type'] = 'application/json';
}
}
if (process.env.NODE_ENV === 'development') {
const { method, url } = config;
Expand Down

0 comments on commit 8f45e5b

Please sign in to comment.