mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 16:39:01 +00:00
* 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>
30 lines
703 B
TypeScript
30 lines
703 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 user is any maintainer or any admin when routing
|
|
*/
|
|
const AuthenticatedAdminRoutes = ({
|
|
children,
|
|
}: IAuthenticatedAdminRoutesProps): JSX.Element | null => {
|
|
const handlePageError = useErrorHandler();
|
|
const { currentUser, isGlobalAdmin } = useContext(AppContext);
|
|
|
|
if (!currentUser) {
|
|
return null;
|
|
}
|
|
|
|
if (!isGlobalAdmin) {
|
|
handlePageError({ status: 403 });
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default AuthenticatedAdminRoutes;
|