Новые правки
This commit is contained in:
parent
75bd562f81
commit
bd0ecb4bd3
1 changed files with 22 additions and 7 deletions
|
|
@ -172,11 +172,26 @@ const { initialLikes = 0, initialDislikes = 0, postId } = Astro.props;
|
||||||
const likesCount = container.querySelector('[data-count="likes"]');
|
const likesCount = container.querySelector('[data-count="likes"]');
|
||||||
const dislikesCount = container.querySelector('[data-count="dislikes"]');
|
const dislikesCount = container.querySelector('[data-count="dislikes"]');
|
||||||
|
|
||||||
if (!pb.authStore.isValid) {
|
// Проверяем авторизацию через API
|
||||||
console.log('pb.authStore.isValid:', pb.authStore.isValid);
|
try {
|
||||||
console.log('pb.authStore.model:', pb.authStore.model);
|
const authResponse = await fetch('/api/auth/me', {
|
||||||
console.log('pb.authStore.token:', pb.authStore.token ? 'exists' : 'none');
|
method: 'GET',
|
||||||
showToast('Войдите, чтобы голосовать', 'warning', 5000, { text: 'Войти', href: '/auth/sign-in' });
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,8 +257,8 @@ const { initialLikes = 0, initialDislikes = 0, postId } = Astro.props;
|
||||||
// Обновляем счетчики
|
// Обновляем счетчики
|
||||||
if (likesCountEl) likesCountEl.textContent = result.likes.toString();
|
if (likesCountEl) likesCountEl.textContent = result.likes.toString();
|
||||||
if (dislikesCountEl) dislikesCountEl.textContent = result.dislikes.toString();
|
if (dislikesCountEl) dislikesCountEl.textContent = result.dislikes.toString();
|
||||||
// Показываем голос пользователя
|
// Показываем голос пользователя (если он есть в ответе)
|
||||||
if (pb.authStore.isValid) {
|
if (result.userVote) {
|
||||||
if (result.userVote === 'like') {
|
if (result.userVote === 'like') {
|
||||||
likeBtn?.classList.add('active');
|
likeBtn?.classList.add('active');
|
||||||
} else if (result.userVote === 'dislike') {
|
} else if (result.userVote === 'dislike') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue