feat: implement AdminRoute for admin access control and enhance UsersPage with user management features
This commit is contained in:
26
src/App.tsx
26
src/App.tsx
@@ -27,6 +27,24 @@ function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
function AdminRoute({ children }: { children: React.ReactNode }) {
|
||||
const { user, loading } = useAuth()
|
||||
|
||||
if (loading) {
|
||||
return <div className="min-h-screen flex items-center justify-center">Loading...</div>
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return <Navigate to="/login" replace />
|
||||
}
|
||||
|
||||
if (user.role !== 'admin') {
|
||||
return <Navigate to="/" replace />
|
||||
}
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
function AppRoutes() {
|
||||
const { user } = useAuth()
|
||||
|
||||
@@ -56,14 +74,14 @@ function AppRoutes() {
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/admin/users" element={
|
||||
<ProtectedRoute>
|
||||
<AdminRoute>
|
||||
<UsersPage />
|
||||
</ProtectedRoute>
|
||||
</AdminRoute>
|
||||
} />
|
||||
<Route path="/admin/settings" element={
|
||||
<ProtectedRoute>
|
||||
<AdminRoute>
|
||||
<SettingsPage />
|
||||
</ProtectedRoute>
|
||||
</AdminRoute>
|
||||
} />
|
||||
</Routes>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user