Новые правки

This commit is contained in:
Web-serfer 2026-05-07 17:16:25 +05:00
parent 79db7c8563
commit a5f208a132
19 changed files with 852 additions and 1 deletions

View file

@ -34,14 +34,31 @@ export default function Comments(props: CommentsProps) {
onMount(async () => {
try {
const response = await fetch("/api/auth/me", {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const url = new URL("/api/auth/me", window.location.origin);
const response = await fetch(url.toString(), {
method: "GET",
credentials: "include",
signal: controller.signal,
});
clearTimeout(timeoutId);
console.log("[Comments] Auth response status:", response.status);
if (!response.ok) {
console.log("[Comments] Auth response not ok, staying unauthenticated");
setIsLoading(false);
return;
}
const data = await response.json();
console.log("[Comments] Auth data:", data);
if (data.authenticated && data.user) {
console.log("[Comments] User authenticated:", data.user.name);
setIsAuthenticated(true);
setCurrentUser({
id: data.user.id,
@ -49,9 +66,12 @@ export default function Comments(props: CommentsProps) {
email: data.user.email,
avatar: data.user.avatar,
});
} else {
console.log("[Comments] User NOT authenticated");
}
} catch (error) {
console.error("[Comments] Ошибка проверки авторизации:", error);
setIsAuthenticated(false);
} finally {
setIsLoading(false);
}