mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
41 lines
877 B
TypeScript
41 lines
877 B
TypeScript
import React, { useContext } from "react";
|
|
import { useErrorHandler } from "react-error-boundary";
|
|
import { AppContext } from "context/app";
|
|
|
|
interface IAuthAnyMaintainerAnyAdminRoutesProps {
|
|
children: JSX.Element;
|
|
}
|
|
|
|
/**
|
|
* Checks if a user is any maintainer or any admin when routing
|
|
*/
|
|
const AuthAnyMaintainerAnyAdminRoutes = ({
|
|
children,
|
|
}: IAuthAnyMaintainerAnyAdminRoutesProps) => {
|
|
const handlePageError = useErrorHandler();
|
|
const {
|
|
currentUser,
|
|
isGlobalAdmin,
|
|
isGlobalMaintainer,
|
|
isAnyTeamAdmin,
|
|
isAnyTeamMaintainer,
|
|
} = useContext(AppContext);
|
|
|
|
if (!currentUser) {
|
|
return null;
|
|
}
|
|
|
|
if (
|
|
!isGlobalAdmin &&
|
|
!isGlobalMaintainer &&
|
|
!isAnyTeamAdmin &&
|
|
!isAnyTeamMaintainer
|
|
) {
|
|
handlePageError({ status: 403 });
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default AuthAnyMaintainerAnyAdminRoutes;
|