// frontend/src/components/PrivateRoute.tsx
import React from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { getSessionToken } from '../services/authService';

interface PrivateRouteProps {
  children: React.ReactNode;
}

const PrivateRoute: React.FC<PrivateRouteProps> = ({ children }) => {
  const sessionToken = getSessionToken();
  const location = useLocation();

  return sessionToken ? <>{children}</> : <Navigate to="/login" state={{ from: location }} replace />;
};

export default PrivateRoute;
