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