Files
EMS-ESP32/interface/src/components/routing/RequireAdmin.tsx
2024-11-22 16:29:31 +01:00

18 lines
502 B
TypeScript

import { useContext } from 'react';
import type { FC } from 'react';
import { Navigate } from 'react-router';
import { AuthenticatedContext } from 'contexts/authentication';
import type { RequiredChildrenProps } from 'utils';
const RequireAdmin: FC<RequiredChildrenProps> = ({ children }) => {
const authenticatedContext = useContext(AuthenticatedContext);
return authenticatedContext.me.admin ? (
<>{children}</>
) : (
<Navigate replace to="/" />
);
};
export default RequireAdmin;