Portal/rsconcept/frontend/src/components/wrap/RequireAuth.tsx
Ivan 76aee5bea7
Some checks failed
Frontend CI / build (22.x) (push) Has been cancelled
F: Implement react-query pt2
2025-01-21 20:33:05 +03:00

29 lines
814 B
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 { useAuth } from '@/backend/auth/useAuth';
import Loader from '../ui/Loader';
import TextURL from '../ui/TextURL';
function RequireAuth({ children }: React.PropsWithChildren) {
const { user, isLoading } = useAuth();
if (isLoading) {
return <Loader key='auth-loader' />;
}
if (user) {
return <>{children}</>;
} else {
return (
<div 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='/' />
</div>
);
}
}
export default RequireAuth;