/** * Protected Route Component * Redirects to login if not authenticated */ import { FC, ReactNode } from 'react'; import { Navigate, useLocation } from 'react-router-dom'; import { useIsAuthenticated, useAuthLoading } from '../modules/auth'; interface ProtectedRouteProps { children: ReactNode; } export const ProtectedRoute: FC = ({ children }) => { const isAuthenticated = useIsAuthenticated(); const isLoading = useAuthLoading(); const location = useLocation(); // Show loading spinner while checking auth state - STC Theme (Gold/Black) if (isLoading) { return (
); } // Redirect to login if not authenticated if (!isAuthenticated) { return ; } return <>{children}; }; /** * Public Route Component * Redirects to dashboard if already authenticated */ interface PublicRouteProps { children: ReactNode; } export const PublicRoute: FC = ({ children }) => { const isAuthenticated = useIsAuthenticated(); const location = useLocation(); // Get the intended destination from state, default to dashboard const from = (location.state as { from?: Location })?.from?.pathname || '/dashboard'; // Redirect to dashboard if already authenticated if (isAuthenticated) { return ; } return <>{children}; };