ConceptPortal-public/rsconcept/frontend/src/components/wrap/RequireAuth.tsx
IRBorisov 63f51e026f
Some checks are pending
Frontend CI / build (18.x) (push) Waiting to run
Improve first loading behavior
2024-06-17 21:31:19 +03:00

35 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { AnimatePresence } from 'framer-motion';
import { useAuth } from '@/context/AuthContext';
import Loader from '../ui/Loader';
import TextURL from '../ui/TextURL';
import AnimateFade from './AnimateFade';
interface RequireAuthProps {
children: React.ReactNode;
}
function RequireAuth({ children }: RequireAuthProps) {
const { user, loading } = useAuth();
return (
<AnimatePresence mode='wait'>
{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}
</AnimatePresence>
);
}
export default RequireAuth;