fleet/frontend/components/AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx
Martavis Parker 349a88e25b
Forcing 404 page where entity ids do not exist (#3833)
* Allow sort by more than one key

* forcing 404 page where entity ids do not exist

* refactored error boundary; handling 404s now

* added 403 overlay; refactored auth wrappers

* fixed test for maintainer

* more efficient fetches; test fixes

* clarify comment

* clean up

Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2022-01-27 14:10:12 -08:00

31 lines
714 B
TypeScript

import React, { useContext } from "react";
import { useErrorHandler } from "react-error-boundary";
import { AppContext } from "context/app";
interface IAuthAnyAdminRoutesProps {
children: JSX.Element;
}
/**
* Checks if a user is any maintainer or any admin when routing
*/
const AuthAnyAdminRoutes = ({
children,
}: IAuthAnyAdminRoutesProps): JSX.Element | null => {
const handlePageError = useErrorHandler();
const { currentUser, isGlobalAdmin, isAnyTeamAdmin } = useContext(AppContext);
if (!currentUser) {
return null;
}
if (!isGlobalAdmin && !isAnyTeamAdmin) {
handlePageError({ status: 403 });
return null;
}
return <>{children}</>;
};
export default AuthAnyAdminRoutes;