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