mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
31 lines
672 B
TypeScript
31 lines
672 B
TypeScript
import React, { useContext } from "react";
|
|
import { useErrorHandler } from "react-error-boundary";
|
|
import { AppContext } from "context/app";
|
|
|
|
interface IAuthenticatedAdminRoutesProps {
|
|
children: JSX.Element;
|
|
}
|
|
|
|
/**
|
|
* Checks if a global admin when routing
|
|
*/
|
|
const AuthenticatedGlobalAdminRoutes = ({
|
|
children,
|
|
}: IAuthenticatedAdminRoutesProps) => {
|
|
const handlePageError = useErrorHandler();
|
|
const { currentUser, isGlobalAdmin } = useContext(AppContext);
|
|
|
|
if (!currentUser) {
|
|
return null;
|
|
}
|
|
|
|
if (!isGlobalAdmin) {
|
|
handlePageError({ status: 403 });
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default AuthenticatedGlobalAdminRoutes;
|