18 lines
380 B
TypeScript
18 lines
380 B
TypeScript
import { Navigate } from "react-router-dom";
|
|
import React from "react";
|
|
|
|
interface AuthorizedRouteProps {
|
|
children: React.ReactNode;
|
|
isAuthorized: boolean;
|
|
}
|
|
|
|
export function AuthorizedRoute({
|
|
children,
|
|
isAuthorized,
|
|
}: AuthorizedRouteProps): JSX.Element {
|
|
if (!isAuthorized) {
|
|
return <Navigate to="/unauthorized" />;
|
|
}
|
|
|
|
return children as React.ReactElement;
|
|
}
|