From 6ab28ae23b26a06ae5bf8653f1be702fe12e236e Mon Sep 17 00:00:00 2001 From: backward99 Date: Sat, 2 Dec 2023 01:55:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20401=EC=97=90=EB=9F=AC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 11 ----------- src/api/axios.ts | 13 ++++++++++++- src/constants/errorMessage.ts | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 63d3b75f..1167b0c4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,10 +3,8 @@ import { createStandaloneToast } from '@chakra-ui/toast'; import { QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { isAxiosError } from 'axios'; import { RouterProvider } from 'react-router-dom'; -import { appPaths } from './config/paths'; import CONSTANTS from './constants/index'; import { ResumeMeErrorResponse } from './types/errorResponse'; -import { deleteCookie } from './utils/cookie'; import router from '~/routes/router'; import theme from '~/theme'; import Fonts from '~/theme/typography/fonts'; @@ -19,15 +17,6 @@ const axiosErrorHandler = (error: Error) => { const { status } = error.response; switch (status) { - case 401: - deleteCookie(CONSTANTS.ACCESS_TOKEN_HEADER); - deleteCookie(CONSTANTS.REFRESH_TOKEN_HEADER); - - alert(CONSTANTS.ERROR_MESSAGES[code]); - - window.location.replace(appPaths.signIn()); - break; - default: if (!(code in CONSTANTS.ERROR_MESSAGES)) { return; diff --git a/src/api/axios.ts b/src/api/axios.ts index ea9f7105..e0e5dfb9 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -1,6 +1,8 @@ import axios from 'axios'; import { environments } from '~/config/environments'; +import { appPaths } from '~/config/paths'; import CONSTANTS from '~/constants'; +import { ErrorMessage } from '~/types/errorResponse'; import { deleteCookie, getCookie, setCookie } from '~/utils/cookie'; export const resumeMeAxios = axios.create({ @@ -26,7 +28,7 @@ resumeMeAxios.interceptors.response.use( }, async function (error) { const statusCode = error.response.status; - const { code } = error.response.data; + const { code }: { code: ErrorMessage } = error.response.data; if (statusCode === 400 && code === 'INVALID_ACCESS_TOKEN') { deleteCookie(CONSTANTS.ACCESS_TOKEN_HEADER); @@ -47,6 +49,15 @@ resumeMeAxios.interceptors.response.use( setCookie(CONSTANTS.ACCESS_TOKEN_HEADER, newAccessToken); } + if (statusCode === 401) { + deleteCookie(CONSTANTS.ACCESS_TOKEN_HEADER); + deleteCookie(CONSTANTS.REFRESH_TOKEN_HEADER); + + alert(CONSTANTS.ERROR_MESSAGES[code]); + + window.location.href = appPaths.signIn(); + } + return Promise.reject(error); }, ); diff --git a/src/constants/errorMessage.ts b/src/constants/errorMessage.ts index 8422ae3e..31324533 100644 --- a/src/constants/errorMessage.ts +++ b/src/constants/errorMessage.ts @@ -16,4 +16,5 @@ export const ERROR_MESSAGES = { GPA_ERROR: '최대 학점은 내 학점보다 커야 해요', MENTOR_NOT_FOUND: '멘토를 찾을 수 없어요 :(', NOT_UPDATE_EVENT: '모집 받는 중에는 수정할 수 없어요.', + MENTOR_ALREADY_APPROVED: '멘토로 승인되었어요. 다시 로그인 해주세요.', }; From 4dda40361a0c582cec9bb0a8d74d522397316102 Mon Sep 17 00:00:00 2001 From: backward99 <86753969+backward99@users.noreply.github.com> Date: Sat, 2 Dec 2023 10:29:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20alert=20=EC=B0=BD=20=EB=91=90?= =?UTF-8?q?=EB=B2=88=20=EB=9C=A8=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- src/api/axios.ts | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 1167b0c4..dc978948 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,7 +17,7 @@ const axiosErrorHandler = (error: Error) => { const { status } = error.response; switch (status) { - default: + case 400: if (!(code in CONSTANTS.ERROR_MESSAGES)) { return; } diff --git a/src/api/axios.ts b/src/api/axios.ts index e0e5dfb9..421669ea 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -50,12 +50,20 @@ resumeMeAxios.interceptors.response.use( } if (statusCode === 401) { - deleteCookie(CONSTANTS.ACCESS_TOKEN_HEADER); - deleteCookie(CONSTANTS.REFRESH_TOKEN_HEADER); + if (code === 'MENTOR_ALREADY_APPROVED') { + if (getCookie(CONSTANTS.ACCESS_TOKEN_HEADER)) { + deleteCookie(CONSTANTS.ACCESS_TOKEN_HEADER); + deleteCookie(CONSTANTS.REFRESH_TOKEN_HEADER); + + alert(CONSTANTS.ERROR_MESSAGES[code]); - alert(CONSTANTS.ERROR_MESSAGES[code]); + window.location.href = appPaths.signIn(); + } + } else { + alert(CONSTANTS.ERROR_MESSAGES.LOGIN_REQUIRED); - window.location.href = appPaths.signIn(); + window.location.href = appPaths.signIn(); + } } return Promise.reject(error);