mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
27 lines
661 B
TypeScript
27 lines
661 B
TypeScript
import React from 'react';
|
|
import { Navigate, Outlet } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useAuth } from '../contexts/AuthContext';
|
|
|
|
interface ProtectedRouteProps {
|
|
redirectPath?: string;
|
|
}
|
|
|
|
const ProtectedRoute: React.FC<ProtectedRouteProps> = ({
|
|
redirectPath = '/login'
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const { auth } = useAuth();
|
|
|
|
if (auth.loading) {
|
|
return <div className="flex items-center justify-center h-screen">{t('app.loading')}</div>;
|
|
}
|
|
|
|
if (!auth.isAuthenticated) {
|
|
return <Navigate to={redirectPath} replace />;
|
|
}
|
|
|
|
return <Outlet />;
|
|
};
|
|
|
|
export default ProtectedRoute; |