- config_service.py: read/write jail config via asyncio.gather, global settings, in-process regex validation, log preview via _read_tail_lines - server_service.py: read/write server settings, flush logs - config router: 9 endpoints for jail/global config, regex-test, logpath management, log preview - server router: GET/PUT settings, POST flush-logs - models/config.py expanded with JailConfig, GlobalConfigUpdate, LogPreview* models - 285 tests pass (68 new), ruff clean, mypy clean (44 files) - Frontend: types/config.ts, api/config.ts, hooks/useConfig.ts, ConfigPage.tsx full implementation (Jails accordion editor, Global config, Server settings, Regex Tester with preview) - Fixed pre-existing frontend lint: JSX.Element → React.JSX.Element (10 files), void/promise patterns in useServerStatus + useJails, no-misused-spread in client.ts, eslint.config.ts self-excluded
38 lines
1023 B
TypeScript
38 lines
1023 B
TypeScript
/**
|
|
* Route guard component.
|
|
*
|
|
* Wraps protected routes. If the user is not authenticated they are
|
|
* redirected to `/login` and the intended destination is preserved so the
|
|
* user lands on it after a successful login.
|
|
*/
|
|
|
|
import { Navigate, useLocation } from "react-router-dom";
|
|
import { useAuth } from "../providers/AuthProvider";
|
|
|
|
interface RequireAuthProps {
|
|
/** The protected page content to render when authenticated. */
|
|
children: React.JSX.Element;
|
|
}
|
|
|
|
/**
|
|
* Render `children` only if the user is authenticated.
|
|
*
|
|
* Redirects to `/login?next=<path>` otherwise so the intended destination is
|
|
* preserved and honoured after a successful login.
|
|
*/
|
|
export function RequireAuth({ children }: RequireAuthProps): React.JSX.Element {
|
|
const { isAuthenticated } = useAuth();
|
|
const location = useLocation();
|
|
|
|
if (!isAuthenticated) {
|
|
return (
|
|
<Navigate
|
|
to={`/login?next=${encodeURIComponent(location.pathname + location.search)}`}
|
|
replace
|
|
/>
|
|
);
|
|
}
|
|
|
|
return children;
|
|
}
|