Новые правки
This commit is contained in:
parent
f6c8a49fbf
commit
4900f81dcf
2 changed files with 22 additions and 9 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import { createSignal, onMount } from "solid-js";
|
||||
import { createSignal, onMount, Show } from "solid-js";
|
||||
|
||||
export default function CommentLock() {
|
||||
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>`;
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ export default function CommentLock() {
|
|||
const hash = window.location.hash;
|
||||
const redirectTo = hash ? `${path}${hash}` : path;
|
||||
setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(redirectTo)}`);
|
||||
setSignupPath(`/auth/sign-up?redirect=${encodeURIComponent(redirectTo)}`);
|
||||
});
|
||||
|
||||
return (
|
||||
|
|
@ -51,13 +53,9 @@ export default function CommentLock() {
|
|||
</a>
|
||||
<p class="mt-3 text-sm text-gray-600">
|
||||
Нет аккаунта?{" "}
|
||||
<a
|
||||
href={`/auth/sign-up?redirect=${encodeURIComponent(window.location.pathname)}`}
|
||||
class="font-medium hover:underline"
|
||||
style="color: #2563eb;"
|
||||
>
|
||||
Зарегистрироваться
|
||||
</a>
|
||||
<Show when={false} fallback={<a href="/auth/sign-up" class="font-medium hover:underline" style="color: #2563eb;">Зарегистрироваться</a>}>
|
||||
<a href={signupPath()} class="font-medium hover:underline" style="color: #2563eb;">Зарегистрироваться</a>
|
||||
</Show>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -26,24 +26,39 @@ if (!post) {
|
|||
// SSR проверка авторизации
|
||||
let isAuthorized = false;
|
||||
const pbAuthCookie = Astro.cookies.get('pb_auth')?.value;
|
||||
if (pbAuthCookie) {
|
||||
|
||||
if (pbAuthCookie && PB_POCKETBASE_URL && PB_POCKETBASE_URL.startsWith('http')) {
|
||||
try {
|
||||
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`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
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