Files
twenty/front/src/modules/auth/components/RequireNotAuth.tsx
Jérémy M c6708b2c1f feat: rewrite auth (#364)
* feat: wip rewrite auth

* feat: restructure folders and fix stories and tests

* feat: remove auth provider and fix tests
2023-06-23 08:49:50 -07:00

57 lines
1012 B
TypeScript

import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { keyframes } from '@emotion/react';
import styled from '@emotion/styled';
import { useIsLogged } from '../hooks/useIsLogged';
const EmptyContainer = styled.div`
align-items: center;
display: flex;
height: 100%;
justify-content: center;
width: 100%;
`;
const fadeIn = keyframes`
from {
opacity: 0;
}
to {
opacity: 1;
}
`;
const FadeInStyle = styled.div`
animation: ${fadeIn} 1s forwards;
opacity: 0;
`;
export function RequireNotAuth({
children,
}: {
children: JSX.Element;
}): JSX.Element {
const navigate = useNavigate();
const isLogged = useIsLogged();
useEffect(() => {
if (isLogged) {
navigate('/');
}
}, [isLogged, navigate]);
if (isLogged) {
return (
<EmptyContainer>
<FadeInStyle>
Please hold on a moment, we're directing you to the app...
</FadeInStyle>
</EmptyContainer>
);
}
return children;
}