ConceptPortal-public/rsconcept/frontend/src/components/RequireAuth.tsx

29 lines
904 B
TypeScript
Raw Normal View History

2023-07-15 17:46:19 +03:00
import { useAuth } from '../context/AuthContext';
import TextURL from './Common/TextURL';
import InfoMessage from './InfoMessage';
interface RequireAuthProps {
children: React.ReactNode
}
2023-07-25 20:27:29 +03:00
function RequireAuth({ children }: RequireAuthProps) {
2023-07-31 23:47:18 +03:00
const { user } = useAuth();
2023-07-15 17:46:19 +03:00
return (
<>
{user && children}
2023-07-25 20:27:29 +03:00
{!user &&
2023-07-15 17:46:19 +03:00
<div className='flex flex-col items-center'>
<InfoMessage message={'Данная функция доступна только зарегистрированным пользователям. Пожалуйста войдите в систему'} />
<div className='flex flex-col items-start'>
<TextURL text='Войти в систему...' href='login' />
<TextURL text='Зарегистрироваться...' href='signup' />
2023-07-25 20:27:29 +03:00
</div>
2023-07-15 17:46:19 +03:00
</div>
}
</>
);
}
2023-07-25 20:27:29 +03:00
export default RequireAuth;