Тесторование Comments.tsx

This commit is contained in:
Web-serfer 2026-05-07 17:41:59 +05:00
parent abaa04ce06
commit 37b87e5b71

View file

@ -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) {
)}
</Show>
{/* DEBUG: показать состояние авторизации */}
<div class="debug-auth-info" style="position:fixed;bottom:0;left:0;background:red;color:white;padding:4px 8px;font-size:10px;z-index:9999;">
isAuthenticated: {isAuthenticated().toString()} | isLoading: {isLoading().toString()}
</div>
{isLoading() ? (
<div class="max-w-4xl mx-auto mt-12 pt-8 border-t border-gray-200">
<div class="flex items-center gap-3 mb-8">