diff --git a/frontend/src/components/blog/comments/CommentLock.tsx b/frontend/src/components/blog/comments/CommentLock.tsx index 9aaa844..55acaa4 100644 --- a/frontend/src/components/blog/comments/CommentLock.tsx +++ b/frontend/src/components/blog/comments/CommentLock.tsx @@ -5,7 +5,9 @@ export default function CommentLock() { onMount(() => { const path = window.location.pathname; - setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(path)}`); + const hash = window.location.hash; + const redirectTo = hash ? `${path}${hash}` : path; + setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(redirectTo)}`); }); return ( @@ -23,7 +25,7 @@ export default function CommentLock() { >
@@ -36,7 +38,7 @@ export default function CommentLock() { @@ -48,7 +50,7 @@ export default function CommentLock() { Зарегистрироваться diff --git a/frontend/src/components/blog/comments/Comments.astro b/frontend/src/components/blog/comments/Comments.astro deleted file mode 100644 index 07d12ef..0000000 --- a/frontend/src/components/blog/comments/Comments.astro +++ /dev/null @@ -1,12 +0,0 @@ ---- -import Comments from "./Comments"; -import type { Props as BaseProps } from "../../../types/comments"; - -interface Props extends BaseProps { - postSlug: string; -} - -const { postSlug } = Astro.props; ---- - - \ No newline at end of file diff --git a/frontend/src/components/blog/comments/Comments.tsx b/frontend/src/components/blog/comments/Comments.tsx index 6299930..6877dfd 100644 --- a/frontend/src/components/blog/comments/Comments.tsx +++ b/frontend/src/components/blog/comments/Comments.tsx @@ -1,7 +1,7 @@ import { createSignal, For, Show, onMount } from "solid-js"; import CommentLock from "./CommentLock"; import CommentForm from "./CommentForm"; -import type { CommentWithReplies } from "../../types/comments"; +import type { CommentWithReplies } from "../../../types/comments"; interface CommentsProps { postSlug: string; diff --git a/frontend/src/components/layout/header/Header.astro b/frontend/src/components/layout/header/Header.astro index 1cdb633..973c0f9 100644 --- a/frontend/src/components/layout/header/Header.astro +++ b/frontend/src/components/layout/header/Header.astro @@ -374,7 +374,8 @@ import { COMPANY } from "@constants"; localStorage.removeItem('auth_token'); localStorage.removeItem('user'); document.querySelector('.header-right')?.classList.remove('auth-active'); - window.location.href = '/'; + // Редирект на текущую страницу + window.location.href = window.location.pathname + window.location.search + window.location.hash; }); // Добавляем класс для изменения порядка diff --git a/frontend/src/pages/api/auth/sign-in.ts b/frontend/src/pages/api/auth/sign-in.ts index 7bff09d..b29afa2 100644 --- a/frontend/src/pages/api/auth/sign-in.ts +++ b/frontend/src/pages/api/auth/sign-in.ts @@ -1,11 +1,11 @@ import type { APIRoute } from 'astro'; import { pb } from '../../../lib/pb'; -export const POST: APIRoute = async ({ request, cookies }) => { +export const POST: APIRoute = async ({ request, cookies, url }) => { try { const data = await request.json(); - const { email, password } = data; + const { email, password, redirect } = data; if (!email || !password) { return new Response(JSON.stringify({ @@ -36,6 +36,12 @@ export const POST: APIRoute = async ({ request, cookies }) => { maxAge: 60 * 60 * 24 * 7, }); + // Определяем URL для редиректа + let redirectUrl = '/'; + if (redirect) { + redirectUrl = redirect; + } + return new Response(JSON.stringify({ success: true, token: authData.token, @@ -43,7 +49,8 @@ export const POST: APIRoute = async ({ request, cookies }) => { id: authData.record.id, name: authData.record.firstName, email: authData.record.email, - } + }, + redirect: redirectUrl }), { status: 200 }); } catch (error: any) { diff --git a/frontend/src/pages/auth/sign-in.astro b/frontend/src/pages/auth/sign-in.astro index f689cc5..f069217 100644 --- a/frontend/src/pages/auth/sign-in.astro +++ b/frontend/src/pages/auth/sign-in.astro @@ -456,7 +456,11 @@ import { SITE_URL } from '@constants'; const response = await fetch('/api/auth/sign-in', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ email, password }), + body: JSON.stringify({ + email, + password, + redirect: new URLSearchParams(window.location.search).get('redirect') + }), }); const data = await response.json(); @@ -469,8 +473,14 @@ import { SITE_URL } from '@constants'; // Сохраняем токен в куку для API document.cookie = `pb_auth=${data.token}; path=/; max-age=${7 * 24 * 60 * 60}; SameSite=Lax`; - // Перенаправляем в личный кабинет - window.location.href = '/cabinet'; + // Перенаправляем на указанный URL или в личный кабинет + const redirectUrl = data.redirect || '/cabinet'; + + // Если есть хэш с ID комментариев - добавляем его к URL + const hash = new URLSearchParams(window.location.search).get('hash'); + const finalUrl = hash ? `${redirectUrl}#comments` : redirectUrl; + + window.location.href = finalUrl; } else if (data.error?.includes('подтверждён')) { showError(emailInput, data.error); } else if (data.error?.includes('пароль')) { diff --git a/frontend/src/pages/blog/[slug].astro b/frontend/src/pages/blog/[slug].astro index 634ef8d..4881438 100644 --- a/frontend/src/pages/blog/[slug].astro +++ b/frontend/src/pages/blog/[slug].astro @@ -1,7 +1,7 @@ --- import ArticleLayout from '@layouts/ArticleLayout.astro'; import { SITE_URL } from '@constants'; -import Comments from '@components/blog/comments/Comments.astro'; +import Comments from '@components/blog/comments/Comments.tsx'; import RelatedPosts from '@components/blog/RelatedPosts.astro'; import ArticleTableOfContents from '@components/blog/ArticleTableOfContents.astro'; import { getPostBySlug, getPosts, getPostImageUrl, getPostVotesStats } from '@lib/pb'; @@ -82,7 +82,7 @@ const heroImage = getPostImageUrl(post);
- +
diff --git a/frontend/src/types/comments.ts b/frontend/src/types/comments.ts index 39a5e76..9841026 100644 --- a/frontend/src/types/comments.ts +++ b/frontend/src/types/comments.ts @@ -15,6 +15,7 @@ export interface CommentRecord { export interface UserRecord { id: string; + firstName?: string; name: string; email: string; avatar?: string;