From 61506f879262c686b3febfacc5c5cf6c1b801330 Mon Sep 17 00:00:00 2001 From: bangsinchur Date: Thu, 20 Feb 2025 16:48:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=91?= =?UTF-8?q?=EC=86=8D=20role=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Gnb/ChargeModal.tsx | 9 +++++---- src/pages/all-receive-plan/index.tsx | 2 +- src/pages/managequo/index.tsx | 2 +- src/pages/profile/maker/edit/informEdit.tsx | 2 +- .../profile/maker/edit/profileEdit/[id].tsx | 2 +- src/pages/profile/maker/mypage/[id].tsx | 2 +- src/pages/quotation-detail/[id].tsx | 2 +- src/pages/receive/index.tsx | 10 ++++------ src/pages/reject-list/index.tsx | 2 +- src/stores/withAuthAccess.tsx | 18 ++++++++++++++++-- 10 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/components/Gnb/ChargeModal.tsx b/src/components/Gnb/ChargeModal.tsx index 11898b28..7de5ac48 100644 --- a/src/components/Gnb/ChargeModal.tsx +++ b/src/components/Gnb/ChargeModal.tsx @@ -45,6 +45,7 @@ export default function ChargeModal({ }); if (paymentStatus.status === "PAID") { setIsChargeModalOpen(false); + window.location.reload(); } }; const handleSubmit: FormEventHandler = async (e) => { @@ -116,7 +117,7 @@ export default function ChargeModal({ }; const isWaitingPayment = paymentStatus.status !== "IDLE"; - console.log('상태메세지',paymentStatus); + console.log("상태메세지", paymentStatus); return ( <> setIsChargeModalOpen(false)}> @@ -125,7 +126,7 @@ export default function ChargeModal({

현재 보유중인 코코넛

코코넛 -

{coconut}개

+

{coconut}개

@@ -177,7 +178,7 @@ export default function ChargeModal({

충전 갯수

{amount ? amount.toLocaleString() : 0}개 /

-

+

{amount ? (amount * 100).toLocaleString() : 0}원

@@ -195,7 +196,7 @@ export default function ChargeModal({ {(paymentStatus.status === "FAILED" || paymentStatus.status === "PAID") && (
-

+

{paymentStatus.status === "FAILED" ? "결제 실패" : "결제 성공"}

diff --git a/src/pages/all-receive-plan/index.tsx b/src/pages/all-receive-plan/index.tsx index f169ead9..d22a4c12 100644 --- a/src/pages/all-receive-plan/index.tsx +++ b/src/pages/all-receive-plan/index.tsx @@ -196,4 +196,4 @@ export function AllReceivePlan() { ); } -export default withAuthAccess(AllReceivePlan); +export default withAuthAccess(AllReceivePlan, "MAKER"); diff --git a/src/pages/managequo/index.tsx b/src/pages/managequo/index.tsx index e9ba8a1e..6cb00195 100644 --- a/src/pages/managequo/index.tsx +++ b/src/pages/managequo/index.tsx @@ -67,4 +67,4 @@ export function ManageQuo() { ); } -export default withAuthAccess(ManageQuo); +export default withAuthAccess(ManageQuo, "MAKER"); diff --git a/src/pages/profile/maker/edit/informEdit.tsx b/src/pages/profile/maker/edit/informEdit.tsx index bfba517d..c91fc9db 100644 --- a/src/pages/profile/maker/edit/informEdit.tsx +++ b/src/pages/profile/maker/edit/informEdit.tsx @@ -5,4 +5,4 @@ export function ProfileEditDreamerPage() { return ; } -export default withAuthAccess(ProfileEditDreamerPage); +export default withAuthAccess(ProfileEditDreamerPage, "MAKER"); diff --git a/src/pages/profile/maker/edit/profileEdit/[id].tsx b/src/pages/profile/maker/edit/profileEdit/[id].tsx index 3f58b988..3531648b 100644 --- a/src/pages/profile/maker/edit/profileEdit/[id].tsx +++ b/src/pages/profile/maker/edit/profileEdit/[id].tsx @@ -9,4 +9,4 @@ export function ProfileEditMakerPage() { return ; } -export default withAuthAccess(ProfileEditMakerPage); +export default withAuthAccess(ProfileEditMakerPage, "MAKER"); diff --git a/src/pages/profile/maker/mypage/[id].tsx b/src/pages/profile/maker/mypage/[id].tsx index f1e92aba..df606bef 100644 --- a/src/pages/profile/maker/mypage/[id].tsx +++ b/src/pages/profile/maker/mypage/[id].tsx @@ -220,4 +220,4 @@ export function MyPage() { ); } -export default withAuthAccess(MyPage); +export default withAuthAccess(MyPage, "MAKER"); diff --git a/src/pages/quotation-detail/[id].tsx b/src/pages/quotation-detail/[id].tsx index a4a681da..df6de7d6 100644 --- a/src/pages/quotation-detail/[id].tsx +++ b/src/pages/quotation-detail/[id].tsx @@ -148,4 +148,4 @@ export function QuotationDetail() { ); } -export default withAuthAccess(QuotationDetail); +export default withAuthAccess(QuotationDetail,"MAKER"); diff --git a/src/pages/receive/index.tsx b/src/pages/receive/index.tsx index 4774de96..09399549 100644 --- a/src/pages/receive/index.tsx +++ b/src/pages/receive/index.tsx @@ -89,12 +89,12 @@ export function Receive() {

-

+

받은 견적 요청

-

전체 플랜

+

전체 플랜

@@ -148,9 +148,7 @@ export function Receive() { ) : (
request_empty -

- 아직 받은 요청이 없어요! -

+

아직 받은 요청이 없어요!

)} @@ -194,4 +192,4 @@ export function Receive() { ); } -export default withAuthAccess(Receive); +export default withAuthAccess(Receive, "MAKER"); diff --git a/src/pages/reject-list/index.tsx b/src/pages/reject-list/index.tsx index 81ae0f4a..786ff113 100644 --- a/src/pages/reject-list/index.tsx +++ b/src/pages/reject-list/index.tsx @@ -67,4 +67,4 @@ export function RejectList() { ); } -export default withAuthAccess(RejectList); +export default withAuthAccess(RejectList,"MAKER"); diff --git a/src/stores/withAuthAccess.tsx b/src/stores/withAuthAccess.tsx index 5d795511..3c709813 100644 --- a/src/stores/withAuthAccess.tsx +++ b/src/stores/withAuthAccess.tsx @@ -3,12 +3,16 @@ import { useRouter } from "next/router"; import { getAccessToken } from "@/utils/tokenUtils"; import loading from "@public/assets/icon_loading.gif"; import Image from "next/image"; +import useAuthStore from "./useAuthStore"; -const withAuthAccess = (WrappedComponent: React.ComponentType) => { +type AllowedRoles = "DREAMER" | "MAKER" | ("DREAMER" | "MAKER")[] | undefined; + +const withAuthAccess = (WrappedComponent: React.ComponentType, allowedRoles?: AllowedRoles) => { const AuthComponent = (props: any) => { const router = useRouter(); const [accessToken, setAccessToken] = useState(null); const [isLoading, setIsLoading] = useState(true); + const { role } = useAuthStore(); useEffect(() => { if (typeof window === "undefined") return; @@ -19,6 +23,15 @@ const withAuthAccess = (WrappedComponent: React.ComponentType) => { router.push("/"); return; } + + if (allowedRoles) { + const roles = Array.isArray(allowedRoles) ? allowedRoles : [allowedRoles]; + if (role !== "guest" && !roles.includes(role as "DREAMER" | "MAKER")) { + router.push("/"); + return; + } + } + setAccessToken(accessToken); } else { if (router.pathname !== "/login" && router.pathname !== "/signup") { @@ -26,7 +39,7 @@ const withAuthAccess = (WrappedComponent: React.ComponentType) => { } } setIsLoading(false); - }, [router]); + }, [router, role, allowedRoles]); if (isLoading) { return ( @@ -44,4 +57,5 @@ const withAuthAccess = (WrappedComponent: React.ComponentType) => { }; return AuthComponent; }; + export default withAuthAccess;