init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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 />;
|
||||
}
|
||||
Reference in New Issue
Block a user