refactor: align frontend ownership boundaries
Close audit gaps across API drift, query policy, UI, and tests.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { Navigate, useLocation } from "react-router";
|
||||
import { useAuth } from "@/features/auth";
|
||||
import { RouteSkeleton } from "./RouteFallback";
|
||||
|
||||
const Protected: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
const { user, ready } = useAuth();
|
||||
const location = useLocation();
|
||||
if (!ready) return <RouteSkeleton variant="shell" />;
|
||||
return user ? (
|
||||
children
|
||||
) : (
|
||||
<Navigate
|
||||
to="/login"
|
||||
state={{ returnTo: `${location.pathname}${location.search}` }}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Public: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
const { user, ready } = useAuth();
|
||||
if (!ready) return <RouteSkeleton variant="shell" />;
|
||||
return user ? <Navigate to="/accounts" replace /> : children;
|
||||
};
|
||||
|
||||
export { Protected, Public };
|
||||
Reference in New Issue
Block a user