Files
PacketStation/frontend/src/components/RequireAuth.tsx
T

11 lines
436 B
TypeScript
Raw Normal View History

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