mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-05-09 15:35:51 +00:00
18 lines
502 B
TypeScript
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;
|