11 lines
385 B
TypeScript
11 lines
385 B
TypeScript
import { Navigate, Outlet, useLocation } from "react-router";
|
|
import { useAuth } from "./AuthContext";
|
|
|
|
export function RequireAuth() {
|
|
const { user, loading } = useAuth();
|
|
const location = useLocation();
|
|
if (loading) return <p className="p-6 text-slate-500">Loading…</p>;
|
|
if (!user) return <Navigate to="/login" replace state={{ from: location }} />;
|
|
return <Outlet />;
|
|
}
|