import { useNavigate } from 'react-router-dom'; import { toast } from 'react-toastify'; import { useAuthContext } from '../providers/authContext'; // Thin wrapper over the auth context (SHOC shape) that layers on the // router/toast side effects components expect from logout. export function useAuth() { const { user, isAuthenticated, isLoading, error, login, logout: clearSession, setError, setLoading, } = useAuthContext(); const navigate = useNavigate(); const logout = () => { clearSession(); toast.info('You have been logged out'); navigate('/login'); }; return { user, isAuthenticated, isLoading, error, login, logout, setError, setLoading, }; }