2023-04-07 15:36:47 +00:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
|
import { useErrorHandler } from "react-error-boundary";
|
|
|
|
|
import { AppContext } from "context/app";
|
|
|
|
|
|
|
|
|
|
interface IAuthAnyMaintainerAdminObserverPlusRoutesProps {
|
|
|
|
|
children: JSX.Element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a user is any maintainer, admin, or observer plus when routing
|
|
|
|
|
*/
|
|
|
|
|
const AuthAnyMaintainerAdminObserverPlusRoutes = ({
|
|
|
|
|
children,
|
|
|
|
|
}: IAuthAnyMaintainerAdminObserverPlusRoutesProps) => {
|
|
|
|
|
const handlePageError = useErrorHandler();
|
2026-01-02 13:06:12 +00:00
|
|
|
const { currentUser, isAnyMaintainerAdminObserverPlus } = useContext(
|
|
|
|
|
AppContext
|
|
|
|
|
);
|
2023-04-07 15:36:47 +00:00
|
|
|
|
|
|
|
|
if (!currentUser) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 13:06:12 +00:00
|
|
|
if (!isAnyMaintainerAdminObserverPlus) {
|
2023-04-07 15:36:47 +00:00
|
|
|
handlePageError({ status: 403 });
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AuthAnyMaintainerAdminObserverPlusRoutes;
|