Новые правки

This commit is contained in:
Web-serfer 2026-05-07 17:59:35 +05:00
parent f6c8a49fbf
commit 4900f81dcf
2 changed files with 22 additions and 9 deletions

View file

@ -1,7 +1,8 @@
import { createSignal, onMount } from "solid-js"; import { createSignal, onMount, Show } from "solid-js";
export default function CommentLock() { export default function CommentLock() {
const [currentPath, setCurrentPath] = createSignal("/auth/sign-in"); const [currentPath, setCurrentPath] = createSignal("/auth/sign-in");
const [signupPath, setSignupPath] = createSignal("/auth/sign-up");
const commentsSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>`; const commentsSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>`;
@ -10,6 +11,7 @@ export default function CommentLock() {
const hash = window.location.hash; const hash = window.location.hash;
const redirectTo = hash ? `${path}${hash}` : path; const redirectTo = hash ? `${path}${hash}` : path;
setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(redirectTo)}`); setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(redirectTo)}`);
setSignupPath(`/auth/sign-up?redirect=${encodeURIComponent(redirectTo)}`);
}); });
return ( return (
@ -51,13 +53,9 @@ export default function CommentLock() {
</a> </a>
<p class="mt-3 text-sm text-gray-600"> <p class="mt-3 text-sm text-gray-600">
Нет аккаунта?{" "} Нет аккаунта?{" "}
<a <Show when={false} fallback={<a href="/auth/sign-up" class="font-medium hover:underline" style="color: #2563eb;">Зарегистрироваться</a>}>
href={`/auth/sign-up?redirect=${encodeURIComponent(window.location.pathname)}`} <a href={signupPath()} class="font-medium hover:underline" style="color: #2563eb;">Зарегистрироваться</a>
class="font-medium hover:underline" </Show>
style="color: #2563eb;"
>
Зарегистрироваться
</a>
</p> </p>
</div> </div>
</div> </div>

View file

@ -26,24 +26,39 @@ if (!post) {
// SSR проверка авторизации // SSR проверка авторизации
let isAuthorized = false; let isAuthorized = false;
const pbAuthCookie = Astro.cookies.get('pb_auth')?.value; const pbAuthCookie = Astro.cookies.get('pb_auth')?.value;
if (pbAuthCookie) {
if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
try { try {
const token = pbAuthCookie.trim(); const token = pbAuthCookie.trim();
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`, { const response = await fetch(`${PB_POCKETBASE_URL}/api/collections/users/auth-refresh`, {
method: 'POST', method: 'POST',
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
signal: controller.signal,
}); });
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 }));