Новые правки
This commit is contained in:
parent
8d83b9d2b4
commit
49f1c74314
3 changed files with 1 additions and 35 deletions
|
|
@ -14,10 +14,7 @@ interface CommentsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Comments(props: CommentsProps) {
|
export default function Comments(props: CommentsProps) {
|
||||||
const isAuthFromSSR = props.isAuthorized ?? false;
|
const [isAuthenticated, setIsAuthenticated] = createSignal(props.isAuthorized ?? false);
|
||||||
console.log("[Comments] SSR isAuthorized:", isAuthFromSSR);
|
|
||||||
const [isAuthenticated, setIsAuthenticated] = createSignal(isAuthFromSSR);
|
|
||||||
console.log("[Comments] Initial isAuthenticated:", isAuthenticated());
|
|
||||||
const [currentUser, setCurrentUser] = createSignal<{
|
const [currentUser, setCurrentUser] = createSignal<{
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -302,11 +299,6 @@ export default function Comments(props: CommentsProps) {
|
||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
{/* DEBUG SSR */}
|
|
||||||
<div class="debug-ssr" style="background:magenta;color:white;padding:5px;margin:5px;font-size:12px;">
|
|
||||||
SSR isAuthorized: {String(props.isAuthorized)} | client isAuthenticated: {String(isAuthenticated())}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{isLoading() ? (
|
{isLoading() ? (
|
||||||
<div class="max-w-4xl mx-auto mt-12 pt-8 border-t border-gray-200">
|
<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">
|
<div class="flex items-center gap-3 mb-8">
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,6 @@ const PB_URL = import.meta.env.PB_POCKETBASE_URL || 'http://127.0.0.1:8090';
|
||||||
|
|
||||||
export const pb = new PocketBase(PB_URL);
|
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 {
|
export interface PostVotes {
|
||||||
id: string;
|
id: string;
|
||||||
post_id: string;
|
post_id: string;
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
console.log('[SSR] Checking auth with PB...');
|
|
||||||
|
|
||||||
const response = await fetch(`${PB_POCKETBASE_URL}/api/collections/users/auth-refresh`, {
|
const response = await fetch(`${PB_POCKETBASE_URL}/api/collections/users/auth-refresh`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -45,20 +43,15 @@ if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
|
||||||
});
|
});
|
||||||
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
console.log('[SSR] Auth response:', response.status);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
isAuthorized = true;
|
isAuthorized = true;
|
||||||
console.log('[SSR] User authorized');
|
|
||||||
} else {
|
} else {
|
||||||
Astro.cookies.delete('pb_auth', { path: '/' });
|
Astro.cookies.delete('pb_auth', { path: '/' });
|
||||||
console.log('[SSR] Auth failed, cookie deleted');
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[SSR Auth] Error:', e);
|
console.error('[SSR Auth] Error:', e);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log('[SSR] No cookie or no PB_URL');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { likes = 0, dislikes = 0 } = await getPostVotesStats(post.id).catch(() => ({ likes: 0, dislikes: 0 }));
|
const { likes = 0, dislikes = 0 } = await getPostVotesStats(post.id).catch(() => ({ likes: 0, dislikes: 0 }));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue