finalizing app adn fixes

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-25 22:58:21 +00:00
parent 4bffede052
commit 91525b8999
19 changed files with 2498 additions and 555 deletions

View File

@@ -0,0 +1,32 @@
import { ReactNode } from "react";
import { Navigate, useLocation } from "react-router-dom";
import { useAuthStore } from "../../store/authStore";
interface AdminRouteProps {
children: ReactNode;
}
/**
* AdminRoute component - guards routes requiring admin or staff privileges
* Redirects to dashboard if user is not admin/staff
*/
export default function AdminRoute({ children }: AdminRouteProps) {
const { user, isAuthenticated } = useAuthStore();
const location = useLocation();
// If not authenticated, ProtectedRoute will handle redirect
if (!isAuthenticated) {
return null;
}
// Check if user is admin or staff
const isAdmin = user?.role === 'admin' || user?.is_staff === true;
if (!isAdmin) {
// Redirect non-admin users to dashboard
console.log('AdminRoute: User is not admin/staff, redirecting to dashboard');
return <Navigate to="/" state={{ from: location }} replace />;
}
return <>{children}</>;
}