Новые правки
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) {
|
||||
const isAuthFromSSR = props.isAuthorized ?? false;
|
||||
console.log("[Comments] SSR isAuthorized:", isAuthFromSSR);
|
||||
const [isAuthenticated, setIsAuthenticated] = createSignal(isAuthFromSSR);
|
||||
console.log("[Comments] Initial isAuthenticated:", isAuthenticated());
|
||||
const [isAuthenticated, setIsAuthenticated] = createSignal(props.isAuthorized ?? false);
|
||||
const [currentUser, setCurrentUser] = createSignal<{
|
||||
id: string;
|
||||
name: string;
|
||||
|
|
@ -302,11 +299,6 @@ export default function Comments(props: CommentsProps) {
|
|||
)}
|
||||
</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() ? (
|
||||
<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">
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
|
|||
const controller = new AbortController();
|
||||
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`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -45,20 +43,15 @@ if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
|
|||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
console.log('[SSR] Auth response:', response.status);
|
||||
|
||||
if (response.ok) {
|
||||
isAuthorized = true;
|
||||
console.log('[SSR] User authorized');
|
||||
} else {
|
||||
Astro.cookies.delete('pb_auth', { path: '/' });
|
||||
console.log('[SSR] Auth failed, cookie deleted');
|
||||
}
|
||||
} catch (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 }));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue