From 10571f8e4b4a41fe6dec435c89f1b840cca8a32b Mon Sep 17 00:00:00 2001 From: koreahghg Date: Mon, 29 Dec 2025 14:22:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EA=B4=80=EB=A6=AC=EC=9E=90=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 10 ++++++++- src/assets/components/ProtectedRoute.tsx | 27 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7cb188ff..4d0cf6e8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -45,8 +45,16 @@ function App() { } /> } /> } /> - } /> + + + + + } + /> } /> diff --git a/src/assets/components/ProtectedRoute.tsx b/src/assets/components/ProtectedRoute.tsx index da2116c7..1e293028 100644 --- a/src/assets/components/ProtectedRoute.tsx +++ b/src/assets/components/ProtectedRoute.tsx @@ -1,15 +1,38 @@ import { Navigate } from 'react-router-dom'; import type { ReactNode } from 'react'; import { useAuth } from '@/contexts/AuthContext'; +import NotFound from '@/pages/404/NotFoundPage'; interface ProtectedRouteProps { children: ReactNode; + requiredRole?: string | string[]; } -export default function ProtectedRoute({ children }: ProtectedRouteProps) { - const { isAuthenticated } = useAuth(); +export default function ProtectedRoute({ + children, + requiredRole, +}: ProtectedRouteProps) { + const { isAuthenticated, user } = useAuth(); if (!isAuthenticated) { return ; } + + if (requiredRole) { + const userRoles: string[] = Array.isArray(user?.role) + ? (user?.role as string[]) + : user?.role + ? [user.role as string] + : []; + + const required = Array.isArray(requiredRole) + ? requiredRole + : [requiredRole]; + + const hasRole = required.some((r) => userRoles.includes(r)); + if (!hasRole) { + return ; + } + } + return <>{children}; } From 92b09758b779ef6391ae23949ced594e49941261 Mon Sep 17 00:00:00 2001 From: koreahghg Date: Mon, 29 Dec 2025 14:24:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20ProtectedRoute=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=EC=9D=98=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20=EB=B0=8F=20Vercel=20=EC=84=A4=EC=A0=95=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- src/assets/components/ProtectedRoute.tsx | 4 ++-- vercel.json | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4d0cf6e8..cf30afcc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -50,7 +50,7 @@ function App() { + } diff --git a/src/assets/components/ProtectedRoute.tsx b/src/assets/components/ProtectedRoute.tsx index 1e293028..723eee1c 100644 --- a/src/assets/components/ProtectedRoute.tsx +++ b/src/assets/components/ProtectedRoute.tsx @@ -21,8 +21,8 @@ export default function ProtectedRoute({ const userRoles: string[] = Array.isArray(user?.role) ? (user?.role as string[]) : user?.role - ? [user.role as string] - : []; + ? [user.role as string] + : []; const required = Array.isArray(requiredRole) ? requiredRole diff --git a/vercel.json b/vercel.json index 0d199b2d..0f32683a 100644 --- a/vercel.json +++ b/vercel.json @@ -1,5 +1,3 @@ { - "rewrites": [ - { "source": "/(.*)", "destination": "/index.html" } - ] + "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }