added frontend for social + feed partiali working
This commit is contained in:
@@ -1,28 +1,22 @@
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { FaSpinner } from "react-icons/fa";
|
||||
import Spinner from "@/components/ui/Spinner";
|
||||
|
||||
export default function PrivateRoute() {
|
||||
const location = useLocation();
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
||||
// Zobraz loading během načítání uživatele
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||||
<div className="text-center">
|
||||
<FaSpinner className="text-blue-500 text-5xl mx-auto mb-4 animate-spin" />
|
||||
<p className="text-gray-600">Načítání...</p>
|
||||
</div>
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<Spinner size={36} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Pokud není přihlášen, redirect na login (ulož původní cestu)
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace state={{ from: location }} />;
|
||||
return <Navigate to="/social/login" replace state={{ from: location }} />;
|
||||
}
|
||||
|
||||
// Uživatel je přihlášen, renderuj chráněný obsah
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
21
frontend/src/routes/PublicOnlyRoute.tsx
Normal file
21
frontend/src/routes/PublicOnlyRoute.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Navigate, Outlet } from "react-router-dom";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import Spinner from "@/components/ui/Spinner";
|
||||
|
||||
export default function PublicOnlyRoute() {
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<Spinner size={36} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Navigate to="/social/feed" replace />;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
Reference in New Issue
Block a user