From 921ab74433edd1b979998900720f9c9cd18192f7 Mon Sep 17 00:00:00 2001 From: kyuran kim <57716832+gxxrxn@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:15:43 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"[#608]=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=EA=B6=8C=ED=95=9C=20=EB=B6=80=EC=97=AC?= =?UTF-8?q?=20(#611)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7f1cd2132b60995e39306b6ad52d7aa073c63629. --- src/app/group/[groupId]/edit/page.tsx | 18 +++++----- src/app/group/[groupId]/join/page.tsx | 6 ++-- src/app/group/create/page.tsx | 6 +--- src/app/profile/me/add/page.tsx | 8 ++--- src/app/profile/me/edit/page.tsx | 14 ++++---- src/app/profile/me/group/page.tsx | 6 ++-- src/hocs/withAuthRequired.tsx | 36 ------------------- .../profile/group/ProfileGroupContainer.tsx | 9 ++--- 8 files changed, 27 insertions(+), 76 deletions(-) delete mode 100644 src/hocs/withAuthRequired.tsx diff --git a/src/app/group/[groupId]/edit/page.tsx b/src/app/group/[groupId]/edit/page.tsx index 607b6ac4..beb48496 100644 --- a/src/app/group/[groupId]/edit/page.tsx +++ b/src/app/group/[groupId]/edit/page.tsx @@ -10,10 +10,12 @@ import { import type { APIGroupDetail, APIEditBookGroup } from '@/types/group'; import { SERVICE_ERROR_MESSAGE } from '@/constants'; -import { isAxiosErrorWithCustomCode } from '@/utils/helpers'; -import useToast from '@/v1/base/Toast/useToast'; +import { + checkAuthentication, + isAxiosErrorWithCustomCode, +} from '@/utils/helpers'; -import withAuthRequired from '@/hocs/withAuthRequired'; +import useToast from '@/v1/base/Toast/useToast'; import BookGroupEditDateForm from '@/v1/bookGroup/edit/BookGroupEditDateForm'; import BookGroupEditIntroduceForm from '@/v1/bookGroup/edit/BookGroupEditIntroduceForm'; import BookGroupEditTitleForm from '@/v1/bookGroup/edit/BookGroupEditTitleForm'; @@ -26,15 +28,13 @@ const BookGroupEditPage = ({ }) => { const router = useRouter(); + const isAuthenticated = checkAuthentication(); + const { data: bookGroupData } = useBookGroupEditCurrentInfo(groupId); const { isOwner, title, description, maxMemberCount, startDate, endDate } = bookGroupData; - /** - * @todo - * 401 페이지 만들기 (접근 권한이 없어요) - */ - if (!isOwner) { + if (!isAuthenticated || !isOwner) { notFound(); } @@ -99,4 +99,4 @@ const BookGroupEditPage = ({ ); }; -export default withAuthRequired(BookGroupEditPage); +export default BookGroupEditPage; diff --git a/src/app/group/[groupId]/join/page.tsx b/src/app/group/[groupId]/join/page.tsx index 08de9554..8750b3bc 100644 --- a/src/app/group/[groupId]/join/page.tsx +++ b/src/app/group/[groupId]/join/page.tsx @@ -6,8 +6,6 @@ import { SubmitHandler, useForm } from 'react-hook-form'; import useJoinBookGroup from '@/hooks/group/useJoinBookGroup'; import SSRSafeSuspense from '@/components/SSRSafeSuspense'; -import withAuthRequired from '@/hocs/withAuthRequired'; - import Loading from '@/v1/base/Loading'; import Input from '@/v1/base/Input'; import InputLength from '@/v1/base/InputLength'; @@ -38,8 +36,6 @@ const JoinBookGroupPage = ({ ); }; -export default withAuthRequired(JoinBookGroupPage); - const BookGroupJoinForm = ({ groupId }: { groupId: number }) => { const router = useRouter(); const { isMember, hasPassword, question, joinBookGroup } = @@ -104,3 +100,5 @@ const BookGroupJoinForm = ({ groupId }: { groupId: number }) => { ); }; + +export default JoinBookGroupPage; diff --git a/src/app/group/create/page.tsx b/src/app/group/create/page.tsx index da9a1401..9151feea 100644 --- a/src/app/group/create/page.tsx +++ b/src/app/group/create/page.tsx @@ -1,11 +1,7 @@ -'use client'; - -import withAuthRequired from '@/hocs/withAuthRequired'; - import CreateBookGroupFunnel from '@/v1/bookGroup/create/CreateBookGroupFunnel'; const GroupCreateFunnelPage = () => { return ; }; -export default withAuthRequired(GroupCreateFunnelPage); +export default GroupCreateFunnelPage; diff --git a/src/app/profile/me/add/page.tsx b/src/app/profile/me/add/page.tsx index ad62e746..8cbfef82 100644 --- a/src/app/profile/me/add/page.tsx +++ b/src/app/profile/me/add/page.tsx @@ -4,10 +4,8 @@ import useAllJobQuery from '@/queries/job/useAllJobQuery'; import { checkAuthentication } from '@/utils/helpers'; -import SSRSafeSuspense from '@/components/SSRSafeSuspense'; -import withAuthRequired from '@/hocs/withAuthRequired'; - import AddJobProfile from '@/v1/profile/AddJobProfile'; +import SSRSafeSuspense from '@/components/SSRSafeSuspense'; const AddJobProfilePage = () => { return ( @@ -17,8 +15,6 @@ const AddJobProfilePage = () => { ); }; -export default withAuthRequired(AddJobProfilePage); - const Contents = () => { const isAuthenticated = checkAuthentication(); const allJobQuery = useAllJobQuery({ enabled: isAuthenticated }); @@ -27,3 +23,5 @@ const Contents = () => { ) : null; }; + +export default AddJobProfilePage; diff --git a/src/app/profile/me/edit/page.tsx b/src/app/profile/me/edit/page.tsx index 970f2f7f..4016132d 100644 --- a/src/app/profile/me/edit/page.tsx +++ b/src/app/profile/me/edit/page.tsx @@ -5,22 +5,22 @@ import useMyProfileQuery from '@/queries/user/useMyProfileQuery'; import { checkAuthentication } from '@/utils/helpers'; +import EditProfile from '@/v1/profile/EditProfile'; import SSRSafeSuspense from '@/components/SSRSafeSuspense'; -import withAuthRequired from '@/hocs/withAuthRequired'; -import EditProfile from '@/v1/profile/EditProfile'; -import Loading from '@/v1/base/Loading'; +/** + * @todo + * Fallback UI 추가하기 + */ const EditProfilePage = () => { return ( - }> + ); }; -export default withAuthRequired(EditProfilePage); - const Contents = () => { const isAuthenticated = checkAuthentication(); const allJobQuery = useAllJobQuery({ enabled: isAuthenticated }); @@ -30,3 +30,5 @@ const Contents = () => { ) : null; }; + +export default EditProfilePage; diff --git a/src/app/profile/me/group/page.tsx b/src/app/profile/me/group/page.tsx index 71358673..cde1a832 100644 --- a/src/app/profile/me/group/page.tsx +++ b/src/app/profile/me/group/page.tsx @@ -4,8 +4,6 @@ import useMyGroupsQuery from '@/queries/group/useMyGroupQuery'; import { checkAuthentication } from '@/utils/helpers'; import SSRSafeSuspense from '@/components/SSRSafeSuspense'; -import withAuthRequired from '@/hocs/withAuthRequired'; - import BackButton from '@/v1/base/BackButton'; import TopNavigation from '@/v1/base/TopNavigation'; import DetailBookGroupCard from '@/v1/bookGroup/DetailBookGroupCard'; @@ -26,8 +24,6 @@ const UserGroupPage = () => { ); }; -export default withAuthRequired(UserGroupPage); - const UserGroupContent = () => { const isAuthenticated = checkAuthentication(); const { data } = useMyGroupsQuery({ enabled: isAuthenticated }); @@ -69,6 +65,8 @@ const UserGroupContent = () => { ); }; +export default UserGroupPage; + const PageSkeleton = () => (
    {Array.from({ length: 4 }).map((_, index) => ( diff --git a/src/hocs/withAuthRequired.tsx b/src/hocs/withAuthRequired.tsx deleted file mode 100644 index db655b3a..00000000 --- a/src/hocs/withAuthRequired.tsx +++ /dev/null @@ -1,36 +0,0 @@ -'use client'; - -import { useRouter } from 'next/navigation'; -import { useEffect, useState } from 'react'; - -import { checkAuthentication } from '@/utils/helpers'; - -const withAuthRequired =

    ( - WrappedComponent: React.ComponentType

    -) => { - const Component = (props: P) => { - const router = useRouter(); - - const [isAuthenticated, setIsAuthenticated] = useState(false); - - useEffect(() => { - const hasAccessToken = checkAuthentication(); - - if (!hasAccessToken) { - router.push('/login'); - } else { - setIsAuthenticated(hasAccessToken); - } - }, [router]); - - if (!isAuthenticated) { - return null; - } else { - return ; - } - }; - - return Component; -}; - -export default withAuthRequired; diff --git a/src/v1/profile/group/ProfileGroupContainer.tsx b/src/v1/profile/group/ProfileGroupContainer.tsx index cb033e86..d066fa50 100644 --- a/src/v1/profile/group/ProfileGroupContainer.tsx +++ b/src/v1/profile/group/ProfileGroupContainer.tsx @@ -1,9 +1,6 @@ import useMyGroupsQuery from '@/queries/group/useMyGroupQuery'; import useMyProfileQuery from '@/queries/user/useMyProfileQuery'; -import type { APIUser } from '@/types/user'; - -import { checkAuthentication } from '@/utils/helpers'; - +import { APIUser } from '@/types/user'; import ProfileGroupPresenter from './ProfileGroupPresenter'; const ProfileGroupContainer = ({ @@ -11,9 +8,7 @@ const ProfileGroupContainer = ({ }: { userId: 'me' | APIUser['userId']; }) => { - const isAuthenticated = checkAuthentication(); - - const { data } = useMyGroupsQuery({ enabled: isAuthenticated }); + const { data } = useMyGroupsQuery(); const { data: { userId: myId }, } = useMyProfileQuery({ enabled: userId === 'me' });