UNPKG

@defikitdotnet/x-ai-combat

Version:

XCombatAI - Social Media Engagement Template for the Agent Framework

21 lines 1.01 kB
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { Navigate, Outlet } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; /** * Protected route component that redirects to login if user is not authenticated */ const ProtectedRoute = ({ redirectPath = '/login', children }) => { const { isAuthenticated, isLoading } = useAuth(); // Show loading spinner while checking auth status if (isLoading) { return (_jsx("div", { className: "flex justify-center items-center h-screen", children: _jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900" }) })); } // Redirect to login if not authenticated if (!isAuthenticated) { return _jsx(Navigate, { to: redirectPath, replace: true }); } // Render children or outlet (for nested routes) return _jsx(_Fragment, { children: children || _jsx(Outlet, {}) }); }; export default ProtectedRoute; //# sourceMappingURL=ProtectedRoute.js.map