diff --git a/frontend/src/components/layout/header/MobileMenu.astro b/frontend/src/components/layout/header/MobileMenu.astro index 3c84e31..799ef26 100644 --- a/frontend/src/components/layout/header/MobileMenu.astro +++ b/frontend/src/components/layout/header/MobileMenu.astro @@ -71,16 +71,6 @@ import { NAV_LINKS, COMPANY } from '@constants'; Ежедневно 9:00–21:00 - - - - - - - - - Вход в аккаунт - @@ -435,7 +425,7 @@ import { NAV_LINKS, COMPANY } from '@constants'; } /* Сообщение о выходе - серое */ - .mobile-login-btn.auth-message.logout-message { +.mobile-login-btn.auth-message.logout-message { background: #6b7280; color: #fff; box-shadow: 0 4px 15px rgba(107, 114, 128, 0.4); @@ -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 - ? '' - : ''; - }; - - // Функция восстановления кнопки "Войти" - 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 = ''; - }; - - // Функция восстановления кнопки "Выйти" - 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 = ''; - - // Добавляем обработчик выхода - 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(); - } }); \ No newline at end of file diff --git a/frontend/src/pages/auth/sign-in.astro b/frontend/src/pages/auth/sign-in.astro index e3e1e0a..48ac856 100644 --- a/frontend/src/pages/auth/sign-in.astro +++ b/frontend/src/pages/auth/sign-in.astro @@ -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);