diff --git a/frontend/src/components/blog/comments/Comments.tsx b/frontend/src/components/blog/comments/Comments.tsx index d0d5c7d..dc8273e 100644 --- a/frontend/src/components/blog/comments/Comments.tsx +++ b/frontend/src/components/blog/comments/Comments.tsx @@ -33,6 +33,21 @@ export default function Comments(props: CommentsProps) { }; onMount(async () => { + if (localStorage.getItem("isAuthenticated") === "false") { + console.log("[Comments] localStorage: explicitly unauthenticated"); + setIsLoading(false); + return; + } + + const debugInfo = { + userAgent: navigator.userAgent, + cookieEnabled: navigator.cookieEnabled, + hasPbAuthCookie: document.cookie.includes('pb_auth'), + url: window.location.href, + localStorageAuth: localStorage.getItem("isAuthenticated"), + }; + console.log("[Comments] Debug info:", debugInfo); + try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5000); @@ -49,6 +64,7 @@ export default function Comments(props: CommentsProps) { console.log("[Comments] Auth response status:", response.status); if (!response.ok) { + localStorage.setItem("isAuthenticated", "false"); console.log("[Comments] Auth response not ok, staying unauthenticated"); setIsLoading(false); return; @@ -58,6 +74,7 @@ export default function Comments(props: CommentsProps) { console.log("[Comments] Auth data:", data); if (data.authenticated && data.user) { + localStorage.setItem("isAuthenticated", "true"); console.log("[Comments] User authenticated:", data.user.name); setIsAuthenticated(true); setCurrentUser({ @@ -67,10 +84,12 @@ export default function Comments(props: CommentsProps) { avatar: data.user.avatar, }); } else { + localStorage.setItem("isAuthenticated", "false"); console.log("[Comments] User NOT authenticated"); } } catch (error) { console.error("[Comments] Ошибка проверки авторизации:", error); + localStorage.setItem("isAuthenticated", "false"); setIsAuthenticated(false); } finally { setIsLoading(false); @@ -311,6 +330,11 @@ export default function Comments(props: CommentsProps) { )} + {/* DEBUG: показать состояние авторизации */} +