mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
20 lines
616 B
TypeScript
20 lines
616 B
TypeScript
import { memo, useContext } from 'react';
|
|
import type { FC } from 'react';
|
|
import { Navigate } from 'react-router';
|
|
|
|
import { fetchLoginRedirect } from 'components/routing/authentication';
|
|
import { AuthenticationContext } from 'contexts/authentication';
|
|
import type { RequiredChildrenProps } from 'utils';
|
|
|
|
const RequireUnauthenticated: FC<RequiredChildrenProps> = ({ children }) => {
|
|
const authenticationContext = useContext(AuthenticationContext);
|
|
|
|
return authenticationContext.me ? (
|
|
<Navigate to={fetchLoginRedirect()} />
|
|
) : (
|
|
<>{children}</>
|
|
);
|
|
};
|
|
|
|
export default memo(RequireUnauthenticated);
|