tambah akaun dari tiap role

This commit is contained in:
2026-05-17 00:53:43 +07:00
parent c205a89b88
commit a904a27934
7 changed files with 330 additions and 243 deletions
+11 -5
View File
@@ -11,7 +11,13 @@ import VerificationPage from "./pages/VerificationPage";
import UsersPage from "./pages/UsersPage";
import SettingsPage from "./pages/SettingsPage";
function ProtectedRoute({ children, adminOnly }: { children: React.ReactNode; adminOnly?: boolean }) {
function ProtectedRoute({
children,
allowedRoles,
}: {
children: React.ReactNode;
allowedRoles?: string[];
}) {
const { user, isLoading } = useAuth();
if (isLoading) {
@@ -26,7 +32,7 @@ function ProtectedRoute({ children, adminOnly }: { children: React.ReactNode; ad
return <Navigate to="/login" replace />;
}
if (adminOnly && user.role !== "admin") {
if (allowedRoles && !allowedRoles.includes(user.role)) {
return <Navigate to="/" replace />;
}
@@ -72,7 +78,7 @@ export default function App() {
<Route
path="/verification"
element={
<ProtectedRoute>
<ProtectedRoute allowedRoles={["admin", "officer"]}>
<VerificationPage />
</ProtectedRoute>
}
@@ -80,7 +86,7 @@ export default function App() {
<Route
path="/users"
element={
<ProtectedRoute adminOnly>
<ProtectedRoute allowedRoles={["admin"]}>
<UsersPage />
</ProtectedRoute>
}
@@ -88,7 +94,7 @@ export default function App() {
<Route
path="/settings"
element={
<ProtectedRoute>
<ProtectedRoute allowedRoles={["admin"]}>
<SettingsPage />
</ProtectedRoute>
}