Новые правки
This commit is contained in:
parent
79db7c8563
commit
a5f208a132
19 changed files with 852 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue