Skip to content

Commit

Permalink
hotfix: 로그인 세션이 만료되었을때 홈화면에 글 리스트가 나오지 않는 이슈 수정 (#714)
Browse files Browse the repository at this point in the history
* hotfix: 로그인 세션이 만료되었을때 홈화면에 글 리스트가 나오지 않는 이슈 수정

* feat: unauthorization error 처리 로직을 useStudylog로 이동한다

* feat: unauthorization 에러시에 alert를 추가한다
  • Loading branch information
sunhpark42 authored Mar 5, 2022
1 parent 72ded70 commit 125a4bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion frontend/src/hooks/useStudylog.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
};

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/MainPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<BannerList bannerList={bannerList} />
Expand Down

0 comments on commit 125a4bd

Please sign in to comment.