import { Navigate, useLocation } from 'react-router-dom' import { useAuthStore } from '../../store/authStore' import { PageLoader } from '../../components/ui/Spinner' const STAFF_ROLES = ['ADMIN', 'SUPPORT', 'ACCOUNTS', 'SUPER_ADMIN'] export function AuthGuard({ children, require: requiredRole }) { const user = useAuthStore(s => s.user) const isLoading = useAuthStore(s => s.isLoading) const location = useLocation() if (isLoading) return if (requiredRole === 'GUEST') { if (!user) return children if (STAFF_ROLES.includes(user.role)) { return } return } if (requiredRole === 'CLIENT') { if (!user) return if (STAFF_ROLES.includes(user.role)) { return } return children } if (requiredRole === 'ADMIN') { if (!user || !STAFF_ROLES.includes(user.role)) { return } return children } return children }