add loader to login

This commit is contained in:
2025-12-05 01:01:13 +05:00
parent 734ca4fce5
commit fc5e65f189
2 changed files with 78 additions and 8 deletions

View File

@ -5,12 +5,15 @@ import MemorySlider from '../components/Login/MemorySlider';
import { useNavigate } from 'react-router-dom';
import PopaPopa from '../components/popa-popa';
import useConfig from '../hooks/useConfig';
import { useState } from 'react';
import { FullScreenLoader } from '../components/FullScreenLoader';
const Login = () => {
const navigate = useNavigate();
const { config, setConfig, saveConfig, handleInputChange } = useConfig();
const { status, validateSession, refreshSession, authenticateWithElyBy } =
useAuth();
const [loading, setLoading] = useState(false);
const authorization = async () => {
console.log('Начинаем процесс авторизации...');
@ -21,6 +24,7 @@ const Login = () => {
return;
}
setLoading(true);
try {
// Проверяем, есть ли сохранённый токен
if (config.accessToken && config.clientToken) {
@ -85,24 +89,31 @@ const Login = () => {
console.log('Авторизация успешно завершена');
navigate('/');
} catch (error) {
} catch (error: any) {
console.log(`ОШИБКА при авторизации: ${error.message}`);
// Очищаем недействительные токены при ошибке
saveConfig({
accessToken: '',
clientToken: '',
});
} finally {
setLoading(false);
}
};
return (
<Box>
<PopaPopa />
<AuthForm
config={config}
handleInputChange={handleInputChange}
onLogin={authorization}
/>
{loading ? (
<FullScreenLoader message="Входим..." />
) : (
<>
<PopaPopa />
<AuthForm
config={config}
handleInputChange={handleInputChange}
onLogin={authorization}
/>
</>
)}
</Box>
);
};