From 521f184c708a7502d541008938313b525aac5965 Mon Sep 17 00:00:00 2001 From: HyeonJin Date: Fri, 8 Nov 2024 16:15:12 +0900 Subject: [PATCH 1/3] :recycle: Refactor Token expiration auto logout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #305 token 만료시 자동로그아웃 --- .../src/pages/ProfilePage/ProfilePage.jsx | 7 ++++- gongjakso/src/service/portfolio_service.js | 12 ++++++-- gongjakso/src/service/post_service.js | 4 ++- gongjakso/src/service/profile_service.js | 29 ++++++++++++++----- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gongjakso/src/pages/ProfilePage/ProfilePage.jsx b/gongjakso/src/pages/ProfilePage/ProfilePage.jsx index 8d55893..ea1ced9 100644 --- a/gongjakso/src/pages/ProfilePage/ProfilePage.jsx +++ b/gongjakso/src/pages/ProfilePage/ProfilePage.jsx @@ -21,6 +21,8 @@ const MAX_PORTFOLIOS = 3; const ProfilePage = () => { const [data, setProfileData] = useState(); + const authenticated = localStorage.getItem('accessToken'); + const [isLoggedIn, setIsLoggedIn] = useState(!!authenticated); const [postContent1, setPostContent1] = useState(); const [postContent2, setPostContent2] = useState(); const [postContent3, setPostContent3] = useState(); @@ -37,6 +39,9 @@ const ProfilePage = () => { const [portfolioList, setPortfolioList] = useState([]); useEffect(() => { + if (!isLoggedIn) { + navigate(`/`); + } getMyInfo().then(response => { setProfileData(response?.data); }); @@ -49,7 +54,7 @@ const ProfilePage = () => { getMyParticipated(1, 2).then(response => { setPostContent3(response?.data?.content); }); - }, []); + }, [isLoggedIn]); useEffect(() => { if (selectedPortfolioId && selectedPortfolioType) { fetchPortfolioDetailsByType( diff --git a/gongjakso/src/service/portfolio_service.js b/gongjakso/src/service/portfolio_service.js index 503fe1e..f297c73 100644 --- a/gongjakso/src/service/portfolio_service.js +++ b/gongjakso/src/service/portfolio_service.js @@ -9,7 +9,9 @@ export const getAllPortfolio = async () => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response.data.code; } }; @@ -49,7 +51,9 @@ export const getPortfolio = async id => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response?.data.code; } }; @@ -62,7 +66,9 @@ export const getExistPortfolio = async (id, type) => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log('Error getting portfolio details:', error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response.data.code; } }; diff --git a/gongjakso/src/service/post_service.js b/gongjakso/src/service/post_service.js index 6f24bbe..ff81c16 100644 --- a/gongjakso/src/service/post_service.js +++ b/gongjakso/src/service/post_service.js @@ -103,7 +103,9 @@ export const getMyPortfolio = async () => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; diff --git a/gongjakso/src/service/profile_service.js b/gongjakso/src/service/profile_service.js index 1173ac5..fc48ee3 100644 --- a/gongjakso/src/service/profile_service.js +++ b/gongjakso/src/service/profile_service.js @@ -14,6 +14,7 @@ export const putMyInfo = async (name, major, job, status, phone) => { }); return response.data; } catch (error) { + console.log(error); throw new Error('나의 정보를 가져올 수 없습니다.'); } }; @@ -25,7 +26,9 @@ export const getMyInfo = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 지원한 게시글을 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -37,7 +40,9 @@ export const getMyRecruiting = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 모집 중인 게시글을 가져올 수 없습니다.', error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -49,7 +54,9 @@ export const getMyApplied = async page => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 지원한 게시글을 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -62,7 +69,9 @@ export const getMyParticipated = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -72,7 +81,9 @@ export const getMyContestScrap = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 공모전 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -82,7 +93,9 @@ export const getMyProjectScrap = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 프로젝트 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; export const getMyTeamScrap = async (page, size) => { @@ -91,6 +104,8 @@ export const getMyTeamScrap = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 프로젝트 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; From a16f225cd1ebac9430a87f7ac6da5eece6c49f78 Mon Sep 17 00:00:00 2001 From: HyeonJin Date: Fri, 8 Nov 2024 16:15:12 +0900 Subject: [PATCH 2/3] :recycle: Refactor Token expiration auto logout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #305 token 만료시 자동로그아웃 --- .../src/pages/ProfilePage/ProfilePage.jsx | 7 ++++- gongjakso/src/service/portfolio_service.js | 12 ++++++-- gongjakso/src/service/post_service.js | 4 ++- gongjakso/src/service/profile_service.js | 29 ++++++++++++++----- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gongjakso/src/pages/ProfilePage/ProfilePage.jsx b/gongjakso/src/pages/ProfilePage/ProfilePage.jsx index 8d55893..ea1ced9 100644 --- a/gongjakso/src/pages/ProfilePage/ProfilePage.jsx +++ b/gongjakso/src/pages/ProfilePage/ProfilePage.jsx @@ -21,6 +21,8 @@ const MAX_PORTFOLIOS = 3; const ProfilePage = () => { const [data, setProfileData] = useState(); + const authenticated = localStorage.getItem('accessToken'); + const [isLoggedIn, setIsLoggedIn] = useState(!!authenticated); const [postContent1, setPostContent1] = useState(); const [postContent2, setPostContent2] = useState(); const [postContent3, setPostContent3] = useState(); @@ -37,6 +39,9 @@ const ProfilePage = () => { const [portfolioList, setPortfolioList] = useState([]); useEffect(() => { + if (!isLoggedIn) { + navigate(`/`); + } getMyInfo().then(response => { setProfileData(response?.data); }); @@ -49,7 +54,7 @@ const ProfilePage = () => { getMyParticipated(1, 2).then(response => { setPostContent3(response?.data?.content); }); - }, []); + }, [isLoggedIn]); useEffect(() => { if (selectedPortfolioId && selectedPortfolioType) { fetchPortfolioDetailsByType( diff --git a/gongjakso/src/service/portfolio_service.js b/gongjakso/src/service/portfolio_service.js index 503fe1e..f297c73 100644 --- a/gongjakso/src/service/portfolio_service.js +++ b/gongjakso/src/service/portfolio_service.js @@ -9,7 +9,9 @@ export const getAllPortfolio = async () => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response.data.code; } }; @@ -49,7 +51,9 @@ export const getPortfolio = async id => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response?.data.code; } }; @@ -62,7 +66,9 @@ export const getExistPortfolio = async (id, type) => { const response = await axiosInstanceV2.get(reqURL); return response; } catch (error) { - console.log('Error getting portfolio details:', error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); return error.response.data.code; } }; diff --git a/gongjakso/src/service/post_service.js b/gongjakso/src/service/post_service.js index 6f24bbe..ff81c16 100644 --- a/gongjakso/src/service/post_service.js +++ b/gongjakso/src/service/post_service.js @@ -103,7 +103,9 @@ export const getMyPortfolio = async () => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; diff --git a/gongjakso/src/service/profile_service.js b/gongjakso/src/service/profile_service.js index 1173ac5..fc48ee3 100644 --- a/gongjakso/src/service/profile_service.js +++ b/gongjakso/src/service/profile_service.js @@ -14,6 +14,7 @@ export const putMyInfo = async (name, major, job, status, phone) => { }); return response.data; } catch (error) { + console.log(error); throw new Error('나의 정보를 가져올 수 없습니다.'); } }; @@ -25,7 +26,9 @@ export const getMyInfo = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 지원한 게시글을 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -37,7 +40,9 @@ export const getMyRecruiting = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 모집 중인 게시글을 가져올 수 없습니다.', error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -49,7 +54,9 @@ export const getMyApplied = async page => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 지원한 게시글을 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -62,7 +69,9 @@ export const getMyParticipated = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log(error); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -72,7 +81,9 @@ export const getMyContestScrap = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 공모전 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; @@ -82,7 +93,9 @@ export const getMyProjectScrap = async () => { const response = await axiosInstance.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 프로젝트 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; export const getMyTeamScrap = async (page, size) => { @@ -91,6 +104,8 @@ export const getMyTeamScrap = async (page, size) => { const response = await axiosInstanceV2.get(reqURL); return response.data; } catch (error) { - console.log('내가 스크랩한 프로젝트 정보를 가져올 수 없습니다.'); + error.response.data.code = 3004 + ? localStorage.removeItem('accessToken') + : console.log(error.response.data.message); } }; From 1268f843a7d1091d09860d2032694da296fcbd1b Mon Sep 17 00:00:00 2001 From: HyeonJin Date: Sun, 10 Nov 2024 18:43:50 +0900 Subject: [PATCH 3/3] :recycle: Add developer and edit index.html tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #305 모집분야 개발자 추가 및 메타태그 변경 --- gongjakso/public/index.html | 6 +++--- gongjakso/src/components/common/CountGuest/CountGuest.jsx | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gongjakso/public/index.html b/gongjakso/public/index.html index a570f14..37adef3 100644 --- a/gongjakso/public/index.html +++ b/gongjakso/public/index.html @@ -23,13 +23,13 @@ gtag('config', 'G-757LG6FY1Q'); -공작소 +공모전 팀빌딩 서비스 | 공작소 gongjakso - + @@ -37,7 +37,7 @@ - + diff --git a/gongjakso/src/components/common/CountGuest/CountGuest.jsx b/gongjakso/src/components/common/CountGuest/CountGuest.jsx index 3e81bda..7312f3e 100644 --- a/gongjakso/src/components/common/CountGuest/CountGuest.jsx +++ b/gongjakso/src/components/common/CountGuest/CountGuest.jsx @@ -6,6 +6,7 @@ const CountGuest = ({ isProject, maxGuests, onApply }) => { const [roles, setRoles] = useState({ 기획: 0, 디자인: 0, + 개발자: 0, ...(isProject && { FE: 0, BE: 0 }), 기타: 0, });