18 lines
496 B
TypeScript
18 lines
496 B
TypeScript
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
|
import { useAuth } from "./use-auth";
|
|
|
|
export function RequireAuth() {
|
|
const { isLoading, user } = useAuth();
|
|
const location = useLocation();
|
|
|
|
if (isLoading) {
|
|
return <div className="rounded-xl border border-slate-200 bg-white p-8 text-sm text-slate-600 shadow-sm">Loading session...</div>;
|
|
}
|
|
|
|
if (!user) {
|
|
return <Navigate replace state={{ from: location.pathname }} to="/login" />;
|
|
}
|
|
|
|
return <Outlet />;
|
|
}
|