Skip to content

Commit

Permalink
refactor: auth 파일의 getRefreshToken 함수를 interceptor 파일로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
areumH committed Jan 14, 2025
1 parent 3ba8b6b commit 720197c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
22 changes: 0 additions & 22 deletions src/api/auth.ts

This file was deleted.

20 changes: 18 additions & 2 deletions src/api/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
import { PATH } from '@/constants/path';
import { NOTICE } from '@/constants/message';
import store from '@/store';
import { ServerResponse } from '@/types/api';
import { tokenActions } from '@/store/auth';
import { getRefreshToken } from './auth';
import { AXIOS, HTTP_STATUS_CODE } from '../constants/api';
import { AXIOS, END_POINT, HTTP_STATUS_CODE } from '../constants/api';
import { HTTPError } from './HttpError';

export interface AxiosErrorResponse {
Expand All @@ -26,6 +26,22 @@ export const axiosInstance = axios.create({
timeout: AXIOS.TIMEOUT,
});

export const axiosRefreshInstance = axios.create({
baseURL,
headers: {
'Content-Type': 'application/json',
},
withCredentials: true,
timeout: AXIOS.TIMEOUT,
});

export const getRefreshToken = async () => {
const { data } = await axiosRefreshInstance.get<ServerResponse>(
`${END_POINT.REFRESH}`,
);
return data;
};

// request interceptor (before request)
axiosInstance.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/common/useTokenRefresh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { useQueryClient } from '@tanstack/react-query';
import { getRefreshToken } from '@/api/auth';
import { getRefreshToken } from '@/api/interceptor';
import { useNewDispatch, useNewSelector } from '@/store';
import { selectAccessToken, tokenActions } from '@/store/auth';
import { useEffect } from 'react';
Expand Down

0 comments on commit 720197c

Please sign in to comment.