Новые правки

This commit is contained in:
Web-serfer 2026-05-07 19:14:09 +05:00
parent 275a1498b4
commit 75bd562f81
2 changed files with 1 additions and 112 deletions

View file

@ -71,16 +71,6 @@ import { NAV_LINKS, COMPANY } from '@constants';
</a>
<span class="contact-label">Ежедневно 9:0021:00</span>
</div>
<!-- Кнопка входа/выхода -->
<a href="/auth/sign-in" class="mobile-login-btn" id="mobile-auth-btn">
<svg id="mobile-auth-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"></path>
<polyline points="10 17 15 12 10 7"></polyline>
<line x1="15" y1="12" x2="3" y2="12"></line>
</svg>
<span id="mobile-auth-text">Вход в аккаунт</span>
</a>
</div>
</div>
</div>
@ -521,100 +511,5 @@ import { NAV_LINKS, COMPANY } from '@constants';
let touchEndX = (e as TouchEvent).changedTouches[0].screenX;
if (touchEndX - touchStartX < -50) closeMenu(); // Свайп влево
});
// Проверка авторизации и настройка кнопки
const authBtn = document.getElementById('mobile-auth-btn');
const authText = document.getElementById('mobile-auth-text');
const authIcon = document.getElementById('mobile-auth-icon');
const token = localStorage.getItem('auth_token');
const userData = localStorage.getItem('user');
// Функция показа сообщения в блоке авторизации
const showAuthMessage = (message: string, isLogin: boolean) => {
if (!authText || !authBtn || !authIcon) return;
authText.textContent = message;
authBtn.classList.remove('logout');
authBtn.classList.add('auth-message');
if (isLogin) {
authBtn.classList.add('login-message');
} else {
authBtn.classList.add('logout-message');
}
authBtn.href = '#';
authIcon.innerHTML = isLogin
? '<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline>'
: '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line>';
};
// Функция восстановления кнопки "Войти"
const restoreLoginButton = () => {
if (!authText || !authBtn || !authIcon) return;
authText.textContent = 'Вход в аккаунт';
authBtn.classList.remove('auth-message', 'login-message', 'logout-message');
authBtn.href = '/auth/sign-in';
authBtn.onclick = null;
authIcon.innerHTML = '<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"></path><polyline points="10 17 15 12 10 7"></polyline><line x1="15" y1="12" x2="3" y2="12"></line>';
};
// Функция восстановления кнопки "Выйти"
const restoreLogoutButton = () => {
if (!authText || !authBtn || !authIcon) return;
authText.textContent = 'Выйти';
authBtn.classList.remove('auth-message', 'login-message', 'logout-message');
authBtn.classList.add('logout');
authBtn.href = '#';
authIcon.innerHTML = '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line>';
// Добавляем обработчик выхода
authBtn.onclick = async (e) => {
e.preventDefault();
// Показываем сообщение о выходе
showAuthMessage('Вы вышли из системы', false);
// Удаляем данные
try {
await fetch('/api/auth/logout', { method: 'POST' });
} catch (err) {}
localStorage.removeItem('auth_token');
localStorage.removeItem('user');
localStorage.removeItem('pocketbase_auth');
// Полностью перезагружаем страницу — SSR проверит куки и обновит состояние
window.location.reload();
};
};
// Проверка флага сообщения о входе
const loginMessage = sessionStorage.getItem('showLoginMessage');
const shouldOpenMenu = sessionStorage.getItem('openMobileMenuOnLoad') === 'true';
if (shouldOpenMenu) {
const overlay = document.getElementById('mobile-menu-overlay');
const body = document.body;
if (overlay) overlay.classList.add('active');
body?.classList.add('menu-open');
sessionStorage.removeItem('openMobileMenuOnLoad');
// Если есть сообщение о входе - показываем его
if (loginMessage) {
showAuthMessage(`Добро пожаловать, ${loginMessage}!`, true);
sessionStorage.removeItem('showLoginMessage');
// Через 3 сек меняем на кнопку выхода
setTimeout(() => {
restoreLogoutButton();
}, 3000);
}
}
// Если авторизован и нет сообщения о входе - показываем кнопку выхода
if (token && userData && !loginMessage) {
restoreLogoutButton();
}
});
</script>

View file

@ -624,12 +624,6 @@ import { SITE_URL } from '@constants';
const hash = new URLSearchParams(window.location.search).get('hash');
const finalUrl = hash ? `${redirectUrl}#comments` : redirectUrl;
// Сохраняем флаг для показа сообщения о входе в мобильном меню
const user = typeof data.user === 'string' ? JSON.parse(data.user) : data.user;
const userName = user?.name || user?.email || 'Пользователь';
sessionStorage.setItem('showLoginMessage', userName);
sessionStorage.setItem('openMobileMenuOnLoad', 'true');
window.location.href = finalUrl;
} else if (data.error?.includes('подтверждён')) {
showError(emailInput, data.error);