@@ -4,16 +4,15 @@ import HTTP_STATUS from './httpStatus';
44
55const api = axios . create ( ) ;
66
7- // api.interceptors.request.use(async config => {
8- // const token = localStorage.getItem('access_token');
7+ api . interceptors . request . use ( async config => {
8+ const token = localStorage . getItem ( 'access_token' ) ;
99
10- // if (token) {
11- // config.headers.Authorization = `Bearer ${token}`;
12- // }
13- // console.log(config);
10+ if ( token ) {
11+ config . headers . Authorization = `Bearer ${ token } ` ;
12+ }
1413
15- // return config;
16- // });
14+ return config ;
15+ } ) ;
1716
1817api . interceptors . response . use (
1918 response => {
@@ -24,14 +23,16 @@ api.interceptors.response.use(
2423 // トークンの有効期限が切れていて、トークン更新要求がない場合
2524 if ( error . response . status === 401 && ! originalRequest . _retry ) {
2625 originalRequest . _retry = true ;
27- const refreshToken = localStorage . getItem ( 'refresh_token' ) ;
26+ const body = {
27+ refresh_token : localStorage . getItem ( 'refresh_token' ) ,
28+ } ;
2829 try {
29- const res = await axios . post ( `${ BASE_URLS . gin } /auth/refresh-token` , {
30- refreshToken,
31- } ) ;
30+ const res = await axios . post (
31+ `${ BASE_URLS . gin } /auth/google/refresh-token` ,
32+ body
33+ ) ;
3234 if ( res . status === 200 ) {
33- const newToken = res . data . access_token ;
34- console . log ( newToken ) ;
35+ const newToken = res . data . data . access_token ;
3536 localStorage . setItem ( 'access_token' , newToken ) ;
3637 api . defaults . headers . common [ 'Authorization' ] = `Bearer ${ newToken } ` ;
3738 // トークンが更新された後、元のリクエストを再実行
@@ -52,10 +53,6 @@ const req = async (
5253 body : object | undefined = undefined
5354) => {
5455 api . defaults . baseURL = BASE_URLS [ server ] ;
55- if ( server === 'nest' ) {
56- api . defaults . headers . common [ 'Authorization' ] =
57- process . env . NEXT_PUBLIC_NEST_TOKEN ;
58- }
5956
6057 if ( typeof body !== 'undefined' ) {
6158 if ( body instanceof FormData ) {
0 commit comments