Refactor: Implement Phase 2 improvements

This commit is contained in:
gpt-engineer-app[bot]
2025-10-15 12:06:51 +00:00
parent 0434aa95ee
commit cdd6b0bbd5
6 changed files with 107 additions and 89 deletions

View File

@@ -1,8 +1,4 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useUserRole } from '@/hooks/useUserRole';
import { useAuth } from '@/hooks/useAuth';
import { useRequireMFA } from '@/hooks/useRequireMFA';
import { useAdminGuard } from '@/hooks/useAdminGuard';
import { MFARequiredAlert } from '@/components/auth/MFARequiredAlert';
import { AdminLayout } from '@/components/layout/AdminLayout';
import { UserManagement } from '@/components/admin/UserManagement';
@@ -10,26 +6,9 @@ import { Skeleton } from '@/components/ui/skeleton';
import { Card, CardContent } from '@/components/ui/card';
export default function AdminUsers() {
const { user, loading: authLoading } = useAuth();
const { isModerator, loading: roleLoading } = useUserRole();
const { needsEnrollment, loading: mfaLoading } = useRequireMFA();
const navigate = useNavigate();
const { isLoading, isAuthorized, needsMFA } = useAdminGuard();
useEffect(() => {
if (!authLoading && !roleLoading) {
if (!user) {
navigate('/auth');
return;
}
if (!isModerator()) {
navigate('/');
return;
}
}
}, [user, authLoading, roleLoading, navigate, isModerator]);
if (authLoading || roleLoading || mfaLoading) {
if (isLoading) {
return (
<AdminLayout>
<div className="space-y-6">
@@ -59,12 +38,11 @@ export default function AdminUsers() {
);
}
if (!user || !isModerator()) {
if (!isAuthorized) {
return null;
}
// MFA enforcement
if (needsEnrollment) {
if (needsMFA) {
return (
<AdminLayout>
<MFARequiredAlert />