Новые правки

This commit is contained in:
Web-serfer 2026-05-07 18:59:32 +05:00
parent 51efcbd00a
commit 275a1498b4
2 changed files with 17 additions and 1 deletions

View file

@ -14,7 +14,9 @@ interface CommentsProps {
}
export default function Comments(props: CommentsProps) {
console.log('[Comments] DEBUG: Received isAuthorized:', props.isAuthorized);
const [isAuthenticated, setIsAuthenticated] = createSignal(props.isAuthorized ?? false);
console.log('[Comments] DEBUG: Initial isAuthenticated:', isAuthenticated());
const [currentUser, setCurrentUser] = createSignal<{
id: string;
name: string;

View file

@ -27,10 +27,16 @@ if (!post) {
let isAuthorized = false;
const pbAuthCookie = Astro.cookies.get('pb_auth')?.value;
console.log('[SSR] DEBUG: Cookie exists:', !!pbAuthCookie);
console.log('[SSR] DEBUG: Cookie value:', pbAuthCookie?.substring(0, 30) + '...');
console.log('[SSR] DEBUG: PB URL:', PB_POCKETBASE_URL);
if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
try {
const token = pbAuthCookie.trim();
console.log('[SSR] DEBUG: Checking auth with token:', token.substring(0, 20) + '...');
const response = await fetch(`${PB_POCKETBASE_URL}/api/collections/users/auth-refresh`, {
method: 'POST',
headers: {
@ -39,17 +45,25 @@ if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
},
});
console.log('[SSR] DEBUG: PB response status:', response.status);
if (response.ok) {
const data = await response.json();
console.log('[SSR] DEBUG: Auth OK, user:', data.record?.email);
isAuthorized = true;
} else {
console.log('[SSR] DEBUG: Auth FAILED, deleting cookie');
Astro.cookies.delete('pb_auth', { path: '/' });
}
} catch (e) {
console.error('[SSR] Auth check error:', e.message);
console.error('[SSR] DEBUG: Error:', e.message);
}
} else {
console.log('[SSR] DEBUG: No cookie or no PB_URL');
}
console.log('[SSR] DEBUG: Final isAuthorized:', isAuthorized);
const { likes = 0, dislikes = 0 } = await getPostVotesStats(post.id).catch(() => ({ likes: 0, dislikes: 0 }));
const views = await getPostViews(post.id).catch(() => 0);