Создана кнопка выхода из системы

This commit is contained in:
Web-serfer 2026-04-15 19:04:27 +05:00
parent 229826acc3
commit 261d5db2d7
13 changed files with 1244 additions and 12 deletions

View file

@ -77,7 +77,7 @@ import { SITE_URL } from '@constants';
<input type="checkbox" name="remember" />
<span>Запомнить меня</span>
</label>
<a href="#" class="forgot-link">Забыли пароль?</a>
<a href="/auth/forgot-password" class="forgot-link">Забыли пароль?</a>
</div>
<button type="submit" class="btn-submit">
@ -447,5 +447,39 @@ import { SITE_URL } from '@constants';
}
console.log('Вход:', { email, password });
const submitBtn = document.querySelector('.btn-submit') as HTMLButtonElement;
submitBtn.disabled = true;
submitBtn.textContent = 'Вход...';
try {
const response = await fetch('/api/auth/sign-in', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
const data = await response.json();
if (response.ok && data.token) {
// Сохраняем токен
localStorage.setItem('auth_token', data.token);
localStorage.setItem('user', JSON.stringify(data.user));
// Перенаправляем в личный кабинет
window.location.href = '/cabinet';
} else if (data.error?.includes('подтверждён')) {
showError(emailInput, data.error);
} else if (data.error?.includes('пароль')) {
showError(passwordInput, data.error);
} else {
showError(passwordInput, data.error || 'Неверный email или пароль');
}
} catch (err) {
showError(passwordInput, 'Ошибка соединения');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Войти';
}
});
</script>