Portal/rsconcept/frontend/src/components/wrap/RequireAuth.tsx

29 lines
957 B
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
import { useAuth } from '@/context/AuthContext';
2024-06-17 21:30:58 +03:00
import Loader from '../ui/Loader';
2024-06-07 20:17:03 +03:00
import TextURL from '../ui/TextURL';
2024-06-17 21:30:58 +03:00
import AnimateFade from './AnimateFade';
2024-06-07 20:17:03 +03:00
2024-09-19 17:48:48 +03:00
function RequireAuth({ children }: React.PropsWithChildren) {
2024-06-17 21:30:58 +03:00
const { user, loading } = useAuth();
return (
2024-12-11 14:59:04 +03:00
<>
2024-06-17 21:30:58 +03:00
{loading ? <Loader key='auth-loader' /> : null}
{!loading && user ? <AnimateFade key='auth-data'>{children}</AnimateFade> : null}
{!loading && !user ? (
<AnimateFade key='auth-no-user' className='flex flex-col items-center gap-1 mt-2'>
<p className='mb-2'>Пожалуйста войдите в систему</p>
<TextURL text='Войти в Портал' href='/login' />
<TextURL text='Зарегистрироваться' href='/signup' />
<TextURL text='Начальная страница' href='/' />
</AnimateFade>
) : null}
2024-12-11 14:59:04 +03:00
</>
2024-06-17 21:30:58 +03:00
);
2024-06-07 20:17:03 +03:00
}
export default RequireAuth;