mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
16 lines
591 B
TypeScript
16 lines
591 B
TypeScript
import { useContext } from 'react';
|
|
import { Navigate } from 'react-router-dom';
|
|
import type { FC } from 'react';
|
|
|
|
import type { RequiredChildrenProps } from 'utils';
|
|
import * as AuthenticationApi from 'api/authentication';
|
|
import { AuthenticationContext } from 'contexts/authentication';
|
|
|
|
const RequireUnauthenticated: FC<RequiredChildrenProps> = ({ children }) => {
|
|
const authenticationContext = useContext(AuthenticationContext);
|
|
|
|
return authenticationContext.me ? <Navigate to={AuthenticationApi.fetchLoginRedirect()} /> : <>{children}</>;
|
|
};
|
|
|
|
export default RequireUnauthenticated;
|