Frontend security / security (push) Successful in 9s
Frontend verify / verify (push) Failing after 37m50s
Frontend security / security (pull_request) Successful in 9s
Frontend verify / verify (pull_request) Failing after 42m10s
Conventional commits / commits (pull_request) Successful in 29s
Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
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 { ready, user } = useAuth();
|
|
const location = useLocation();
|
|
if (!ready) return <RouteSkeleton variant="shell" />;
|
|
return user
|
|
? (
|
|
<>{children}</>
|
|
)
|
|
: (
|
|
<Navigate
|
|
replace
|
|
state={{ returnTo: `${location.pathname}${location.search}` }}
|
|
to="/login"
|
|
/>
|
|
);
|
|
};
|
|
|
|
const Public: FC<PropsWithChildren> = (props) => {
|
|
const { children } = props;
|
|
const { ready, user } = useAuth();
|
|
const location = useLocation();
|
|
|
|
if (!ready) return <RouteSkeleton variant="shell" />;
|
|
const requested = (location.state as null | { returnTo?: string })?.returnTo;
|
|
const returnTo
|
|
= typeof requested === "string"
|
|
&& requested.startsWith("/")
|
|
&& !requested.startsWith("//")
|
|
? requested
|
|
: "/accounts";
|
|
return user ? <Navigate replace to={returnTo} /> : <>{children}</>;
|
|
};
|
|
|
|
export { Protected, Public };
|