Новые правки

This commit is contained in:
Web-serfer 2026-05-07 18:28:02 +05:00
parent 49f1c74314
commit 7aa8d60736
2 changed files with 37 additions and 7 deletions

View file

@ -14,8 +14,10 @@ interface CommentsProps {
}
export default function Comments(props: CommentsProps) {
console.log('[Comments] SSR isAuthorized:', props.isAuthorized);
const [isAuthenticated, setIsAuthenticated] = createSignal(props.isAuthorized ?? false);
const [currentUser, setCurrentUser] = createSignal<{
console.log('[Comments] Initial isAuthenticated:', isAuthenticated());
const [currentUser, setCurrentUser] = createSignal<{
id: string;
name: string;
email: string;
@ -52,6 +54,7 @@ export default function Comments(props: CommentsProps) {
const data = await response.json();
if (data.authenticated && data.user) {
setIsAuthenticated(true);
setCurrentUser({
id: data.user.id,
name: data.user.name || "Пользователь",
@ -67,6 +70,7 @@ export default function Comments(props: CommentsProps) {
const loadComments = async () => {
try {
setIsLoading(true);
const response = await fetch(
`/api/comments?post_slug=${encodeURIComponent(props.postSlug)}&parent=null`,
{
@ -101,6 +105,8 @@ export default function Comments(props: CommentsProps) {
setComments(commentsWithReplies);
} catch (error) {
console.error("[Comments] Ошибка загрузки комментариев:", error);
} finally {
setIsLoading(false);
}
};
@ -299,6 +305,11 @@ export default function Comments(props: CommentsProps) {
)}
</Show>
{/* DEBUG */}
<div style="background:#333;color:white;padding:5px;font-size:10px;">
SSR isAuthorized: {String(props.isAuthorized)} | client isAuth: {String(isAuthenticated())}
</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">

View file

@ -5,6 +5,25 @@ const PB_URL = import.meta.env.PB_POCKETBASE_URL || 'http://127.0.0.1:8090';
export const pb = new PocketBase(PB_URL);
if (typeof window !== 'undefined') {
const token = localStorage.getItem('auth_token');
const userStr = localStorage.getItem('user');
// Инициализируем куку из localStorage если её нет
if (token && !document.cookie.includes('pb_auth')) {
document.cookie = `pb_auth=${token}; path=/; max-age=${7 * 24 * 60 * 60}; SameSite=Lax`;
}
if (token && userStr) {
try {
const user = JSON.parse(userStr);
pb.authStore.save(token, user);
} catch (e) {
console.error('Failed to restore auth:', e);
}
}
}
export interface PostVotes {
id: string;
post_id: string;