mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
29 lines
688 B
TypeScript
29 lines
688 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 global or team admin when routing
|
|
*/
|
|
const AuthAnyAdminRoutes = ({ children }: IAuthAnyAdminRoutesProps) => {
|
|
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;
|