From bd0ecb4bd31df77d65cb91cf7a64b805beeeba6c Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Thu, 7 May 2026 19:25:30 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/blog/PostReactionButtons.astro | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/blog/PostReactionButtons.astro b/frontend/src/components/blog/PostReactionButtons.astro index e36fe95..c056027 100644 --- a/frontend/src/components/blog/PostReactionButtons.astro +++ b/frontend/src/components/blog/PostReactionButtons.astro @@ -172,11 +172,26 @@ const { initialLikes = 0, initialDislikes = 0, postId } = Astro.props; const likesCount = container.querySelector('[data-count="likes"]'); const dislikesCount = container.querySelector('[data-count="dislikes"]'); - if (!pb.authStore.isValid) { - console.log('pb.authStore.isValid:', pb.authStore.isValid); - console.log('pb.authStore.model:', pb.authStore.model); - console.log('pb.authStore.token:', pb.authStore.token ? 'exists' : 'none'); - showToast('Войдите, чтобы голосовать', 'warning', 5000, { text: 'Войти', href: '/auth/sign-in' }); + // Проверяем авторизацию через API + try { + const authResponse = await fetch('/api/auth/me', { + method: 'GET', + credentials: 'include', + }); + + if (!authResponse.ok) { + showToast('Авторизуйтесь, чтобы голосовать', 'warning', 5000, { text: 'Войти', href: '/auth/sign-in' }); + return; + } + + const authData = await authResponse.json(); + if (!authData.authenticated || !authData.user) { + showToast('Авторизуйтесь, чтобы голосовать', 'warning', 5000, { text: 'Войти', href: '/auth/sign-in' }); + return; + } + } catch (e) { + console.error('Auth check error:', e); + showToast('Авторизуйтесь, чтобы голосовать', 'warning', 5000, { text: 'Войти', href: '/auth/sign-in' }); return; } @@ -242,8 +257,8 @@ const { initialLikes = 0, initialDislikes = 0, postId } = Astro.props; // Обновляем счетчики if (likesCountEl) likesCountEl.textContent = result.likes.toString(); if (dislikesCountEl) dislikesCountEl.textContent = result.dislikes.toString(); - // Показываем голос пользователя - if (pb.authStore.isValid) { + // Показываем голос пользователя (если он есть в ответе) + if (result.userVote) { if (result.userVote === 'like') { likeBtn?.classList.add('active'); } else if (result.userVote === 'dislike') {