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

29 lines
814 B
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
2025-01-21 20:33:05 +03:00
import { useAuth } from '@/backend/auth/useAuth';
2024-06-07 20:17:03 +03:00
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-09-19 17:48:48 +03:00
function RequireAuth({ children }: React.PropsWithChildren) {
2025-01-21 20:33:05 +03:00
const { user, isLoading } = useAuth();
2024-06-17 21:30:58 +03:00
2025-01-21 20:33:05 +03:00
if (isLoading) {
2024-12-12 13:17:24 +03:00
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>
);
}
2024-06-07 20:17:03 +03:00
}
export default RequireAuth;