todos-contra-el-fuego-web/imports/ui/components/Authenticated/Authenticated.js
vjrj e2d13ca64c deps: react-router-dom 4 -> 6 (history 5, react-router-bootstrap 0.26)
Removes the Router/Switch/Route/Link/LinkContainer legacy-context
warnings. Keeps the shared history singleton (used outside React by
NotificationsObserver + Utils/location) via unstable_HistoryRouter, and
bridges v6 hooks back to v4-shaped history/match/location props with a
new withRouterCompat HOC so the ~20 class pages stay untouched.

- <Switch> -> <Routes>, component= -> element=
- Authenticated/Public -> guard components (children or <Navigate replace>)
- LocationListener -> useLocation + useEffect function
- regex route /fire/:type(active|archive|alert)/:id -> /fire/:type/:id
- history.listen callback is ({ location }) in history v5

Browser-verified: SPA nav, /subscriptions->/login auth redirect,
deep-link /fire/archive/:id (params), browser back/forward. REST smoke
byte-identical.
2026-07-21 13:00:15 +02:00

16 lines
524 B
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Navigate } from 'react-router-dom';
// v6 route guard: rendered as a route `element` wrapping the real page.
// Renders its children when authenticated, otherwise redirects to /login.
const Authenticated = ({ authenticated, children }) => (
authenticated ? children : <Navigate to="/login" replace />
);
Authenticated.propTypes = {
authenticated: PropTypes.bool.isRequired,
children: PropTypes.node.isRequired
};
export default Authenticated;