import { Navigate, Outlet } from 'react-router-dom';
import { useContext } from 'react';
import { AuthContext } from './AuthProvider';
import LoadingScreen from '../components/LoadingScreen';

function PublicRoute() {
  const { authorized } = useContext(AuthContext);

  if (authorized === null) {
    return <LoadingScreen />;
  }

  return authorized ? <Navigate to="/chat" replace /> : <Outlet />;
}

export default PublicRoute;
