11 lines
436 B
TypeScript
11 lines
436 B
TypeScript
import { Navigate, Outlet } from "react-router";
|
|||
|
|
import { useAuth } from "../auth/useAuth";
|
||
|
|
|
||
|
|
/** Routes below need a session. Signed out goes to /signin. A locked session stays, under the lock screen. */
|
||
|
|
export function RequireAuth() {
|
||
|
|
const { status } = useAuth();
|
||
|
|
if (status === "loading") return <div className="empty">Loading</div>;
|
||
|
|
if (status === "anonymous") return <Navigate to="/signin" replace />;
|
||
|
|
return <Outlet />;
|
||
|
|
}
|