Files
ai-wave-02/apps/web/src/auth/require-auth.tsx
T
2026-09-03 22:02:52 +09:00

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 />;
}