mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
d8143c6ff4
* refactor: fix child selector warnings * refactor: update react-router-dom * refactor: use BrowserRouter as in react-router docs * refactor: replace Redirect with Navigate * refactor: replace Switch with Routes * refactor: replace useHistory with useNavigate * refactor: replace useParams types with useRequiredPathParam * refactor: replace NavLink activeStyle with callback * refactor: fix matchPath arg order * refactor: Remove unused link state * refactor: delete broken snapshot test * refactor: render 404 page without redirect * refactor: normalize path parameter names * refactor: fix Route component usage
19 lines
523 B
TypeScript
19 lines
523 B
TypeScript
import { IRoute } from 'interfaces/route';
|
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
|
import { LoginRedirect } from 'component/common/LoginRedirect/LoginRedirect';
|
|
|
|
interface IProtectedRouteProps {
|
|
route: IRoute;
|
|
}
|
|
|
|
export const ProtectedRoute = ({ route }: IProtectedRouteProps) => {
|
|
const { user } = useAuthUser();
|
|
const isLoggedIn = Boolean(user?.id);
|
|
|
|
if (!isLoggedIn && route.type === 'protected') {
|
|
return <LoginRedirect />;
|
|
}
|
|
|
|
return <route.component />;
|
|
};
|