From 125a4bdf56bec0966a6376b74179489a3fb403d8 Mon Sep 17 00:00:00 2001 From: sunny <67677561+sunhpark42@users.noreply.github.com> Date: Sat, 5 Mar 2022 14:54:19 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=84=B8=EC=85=98=EC=9D=B4=20=EB=A7=8C=EB=A3=8C=EB=90=98?= =?UTF-8?q?=EC=97=88=EC=9D=84=EB=95=8C=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20=EA=B8=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EB=82=98=EC=98=A4=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=9D=B4?= =?UTF-8?q?=EC=8A=88=20=EC=88=98=EC=A0=95=20(#714)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * hotfix: 로그인 세션이 만료되었을때 홈화면에 글 리스트가 나오지 않는 이슈 수정 * feat: unauthorization error 처리 로직을 useStudylog로 이동한다 * feat: unauthorization 에러시에 alert를 추가한다 --- frontend/src/hooks/useStudylog.js | 13 ++++++++++++- frontend/src/pages/MainPage/index.js | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useStudylog.js b/frontend/src/hooks/useStudylog.js index 192f38e38..7ba7de38a 100644 --- a/frontend/src/hooks/useStudylog.js +++ b/frontend/src/hooks/useStudylog.js @@ -1,4 +1,6 @@ -import { useState } from 'react'; +import { useContext, useState } from 'react'; + +import { UserContext } from '../contexts/UserProvider'; import { ERROR_MESSAGE } from '../constants/message'; import { requestGetStudylog, @@ -7,17 +9,26 @@ import { requestEditStudylog, } from '../service/requests'; import useMutation from './useMutation'; +import ERROR_CODE from '../constants/errorCode'; const useStudylog = (defaultValue) => { const [response, setResponse] = useState(defaultValue); const [error, setError] = useState(''); + const { onLogout } = useContext(UserContext) + const onSuccess = (data) => { setResponse(data); + setError(''); }; const onError = (error) => { console.error(error); + + if (error.code === ERROR_CODE.EXPIRED_ACCESS_TOKEN) { + onLogout(); + } + setError(ERROR_MESSAGE[error.code] ?? ERROR_MESSAGE.DEFAULT); }; diff --git a/frontend/src/pages/MainPage/index.js b/frontend/src/pages/MainPage/index.js index 924c57e14..3f6d6433b 100644 --- a/frontend/src/pages/MainPage/index.js +++ b/frontend/src/pages/MainPage/index.js @@ -14,12 +14,18 @@ import { UserContext } from '../../contexts/UserProvider'; const MainPage = () => { const { user } = useContext(UserContext); const { accessToken } = user; - const { response: recentStudylogs, getAllData: fetchRecentStudylogs } = useStudylog([]); + const { response: recentStudylogs, error: recentStudylogsError, getAllData: fetchRecentStudylogs } = useStudylog([]); useEffect(() => { fetchRecentStudylogs({ query: { type: 'searchParams', data: 'size=3' }, accessToken }); }, [accessToken]); + useEffect(() => { + if (recentStudylogsError) { + alert(recentStudylogsError) + } + }, [recentStudylogsError]) + return ( <>